开发者

How is extra script layer implemented?

If you have ever worked on alfresco, you must know the web script layer in it, my question is how does alfresco implement this ? What framework does it use?

If you don't know alfresco, then my question is : how can I implement a script layer to expose my service layer as a JavaSc开发者_JAVA技巧ript style object?

With the layer, I can write the following code :

Var test = person.createPerson(556687);

Test...... Thanks in advance!


The webscript layer used in the Alfresco server was developed by Alfresco itself and is now part of Spring. The current version can be found in the Spring Surf project as Spring Surf Webscripts.

To expose your own Java class as Javascript object you have to extend the BaseProcessorExtension class and register it with the following spring bean configuration:

<bean id="yourJavascriptBean" parent="baseJavaScriptExtension" class="com.example.MyJavaService">
  <property name="extensionName" value="customobject" />
</bean>

This will register your service as the object customobject. An example for registering the Alfresco serviceRegistry can be found in Alfresco wiki. You might also want to check out the source code for existing Alfresco services like the Javascript People API.

Keep in mind that this registers the object globally in the javascript engine which might alter the behavior of the existing javascript code.


Alfresco uses Mozzila Rhino that provides the Java Script engine that exposes Java Objects through Java Script.


You can use Direct Web Remoting (DWR). From their site:

DWR is a Java library that enables Java on the server and JavaScript in a browser to interact and call each other as simply as possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜