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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -