ScriptEngineManager not passing binded variables?

I was trying to bind a variable but the javascript engine is saying there is no method getRow() on my java object which I do have so I don't get why this code does not work context.getRow() in the javascript is the issue. public static void main(String[] args) throws ScriptException, NoSuchMethodException { Map jsonRow = new HashMap(); jsonRow.put("temp", "56"); TriggerContext ctx = new TriggerContext(jsonRow , null); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("javascript"); engine.put("context", ctx); //Object result = compiledScript.eval(); engine.eval("function trigger() { var t = context.getRow(); var val = t['temp']; if(val > 55) return false; else return true; }"); Invocable inv = (Invocable) engine; // invoke the global function named "hello" Object result = inv.invokeFunction("trigger" ); System.out.println("result="+result); System.out.println("type="+result.getClass()); }

以上就是ScriptEngineManager not passing binded variables?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准