access javascript method from java side -
i have javascript resource , apply rhino script engine call method java side.
(function( global ){ var result; (result = function( val ) { this.tpl = val || '' ; }).prototype = { get: function () { return this.tpl ; } }; } ( window ) ) ;
this way how did on java side, how can call 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 call method in above script, doesn't work inv.invokemethod(obj, "get", new object[] {} ); }
a possible workaround store result in script variable , read var jsengine.get("myresult");
Comments
Post a Comment