views:

56

answers:

3

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 JavaScript style object?

With the layer, I can write the following code :

Var test = person.createPerson(556687);

Test...... Thanks in advance!

A: 

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.

Faisal Feroz
It seems that the library is a Ajax library( remote call) but not direct map the service to JavaScript object and can be used in server side
MemoryLeak
+1  A: 

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.

Florian
Thanks, but I want know how to implement the mechanism but not how to configure it.
MemoryLeak
A: 

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

MemoryLeak