简体   繁体   English

Java方法无法使用Freemarker从Javascript执行

[英]Java method doesnt execute from Javascript using Freemarker

I am trying to execute Java method in Javascript over object which I get from Java code using Freemarker. 我试图对我使用Freemarker从Java代码获得的对象执行Javascript中的Java方法。 I have java object "actual_id" of type "Settinga" and method "setActual_id" which just sets one attribute of the object. 我有类型为“ Settinga”的java对象“ actual_id”和方法“ setActual_id”,该方法仅设置对象的一个​​属性。 This is my call of the method in js: 这是我对js中的方法的调用:

var idd = ${actual_id}.setActual_id(variable);

Instead of execution in html code I see: 而不是在html代码中执行,我看到了:

javaclassurl$Settinga@5beccfce.setActual_id(variable);

And there is error: myFunction is not defined at HTMLButtonElement.onclick 并且有一个错误:myFunction未在HTMLButtonElement.onclick上定义

Why it doesnt execute? 为什么不执行? Following call is executed as expected but I need to include variable: 以下调用按预期执行,但我需要包含变量:

var idd = "${actual_id.setActual_id("aaa01dd3-abe4-4d50-a69e-62b04199b7c5")}";

I understand that Freemarker expressions are translated during page generation and when I use just string its easily interpreted and can be executed but during page generation my variable which I want to include in the call isnt known so need to make execution somehow else... 我了解Freemarker表达式会在页面生成过程中进行翻译,当我只使用字符串时,它很容易解释并可以执行,但是在页面生成过程中,我想包含在调用中的变量是未知的,因此需要以其他方式执行...

因为它的工作方式是这样的:FreeMarker在服务器上执行,将所有${...}解析为纯文本,然后客户端的浏览器获取生成的HTML并执行JavaScript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM