I have a javascript resource and apply Rhino Script Engine to call a method from java side.
(function( global ){
var Result;
(Result = function( val ) {
this.tpl = val || '' ;
}).prototype = {
get: function ()
{
return this.tpl ;
}
};
} ( window ) ) ;
This is the way how i did it on java side, how can i call get method in above script ?
@Test
public void testCallJSMethod() throws Exception {
String jsResource = getJSResource();
jsEngine.put("window", "window");
jsEngine.put("window.Result", "Result");
jsEngine.eval(jsResource);
Invocable inv = (Invocable) jsEngine;
Object obj = jsEngine.get("window.Result");
assertEquals(true, obj != null);
//try to call get method in above script, but it doesn't work
inv.invokeMethod(obj, "get", new Object[] {} );
}
A possible workaround for this is to store the result in a script variable and read that var with jsEngine.get("myResult");