简体   繁体   中英

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. I have java object "actual_id" of type "Settinga" and method "setActual_id" which just sets one attribute of the object. This is my call of the method in js:

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

Instead of execution in html code I see:

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

And there is error: myFunction is not defined at 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在服务器上执行,将所有${...}解析为纯文本,然后客户端的浏览器获取生成的HTML并执行JavaScript。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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