cancel
Showing results for 
Search instead for 
Did you mean: 

DeclarativeWebScript and public methods

alrice
Champ in-the-making
Champ in-the-making
Hey this is neat!   Am I wastefully re-inventing something that is already possible in DeclarativeWebScript? I have some public  string manipulation methods in my DeclarativeWebScript subclass. I want to be able to call them from the javascript . AFAIK the methods are not exposed anywhere to the javascript so I decided to set a reference to the DeclarativeWebScript instance, in the model:
protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {

// put this object as well, so the javascript can
// access it's public methods
model.put("oJavaParent", this);

}
Then in the Java-backed web script ( javascript) I can call methods like this and it works.
var x = oJavaParent.mypublicmethod(s);
I assume this would really speed up things like string formatting and concatenation that need to be called frequently. Unless there is a cost to the javascript-java bridging. I don't know how one would profile it.
2 REPLIES 2

pmonks
Star Contributor
Star Contributor
Yeah Rhino (the JS interpreter embedded in Alfresco) has pretty good Java integration, and although there might be some overhead in JS -> Java calls, it's probably pretty quick once the JVM has warmed up (I'm assuming a lot of the bridging code would get JITted before too long).

In terms of profiling, I'd probably profile the entire Web Script and then compare the use of Javascript idioms with calls through to Java.  Hopefully you'll find that the execution time is dominated by something else entirely (eg. network I/O).  :wink:

You've probably already seen this, but there's more documentation on this kind of thing at:
Cheers,
Peter

alrice
Champ in-the-making
Champ in-the-making
OK thanks!  😎