MemoryLeak
MemoryLeak

Reputation: 7318

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

With the layer, I can write the following code :

Var test = person.createPerson(556687);

Test...... Thanks in advance!

Upvotes: 3

Views: 384

Answers (3)

MemoryLeak
MemoryLeak

Reputation: 7318

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

Upvotes: 1

Florian
Florian

Reputation: 1281

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.

Upvotes: 4

Faisal Feroz
Faisal Feroz

Reputation: 12785

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.

Upvotes: 0

Related Questions