【发布时间】:2019-03-26 17:51:58
【问题描述】:
我正在尝试将一个值传递给我的 javascript 函数,但该函数调用取决于一个布尔变量。在我最近升级到 thymeleaf security 5 之前,我一直运行良好。
这是代码 sn-p。
<body th:onload="${timerEnabled} ? 'javascript:runTimer(\'' + ${timeRemaining} + '\');'">
timerEnabled 必须为 true 才能完成函数调用,但 thymeleaf 现在会抛出异常
org.thymeleaf.exceptions.TemplateProcessingException: Only variable expressions returning numbers or booleans are allowed in this context, any other datatypes are not trusted in the context of this expression, including Strings or any other object that could be rendered as a text literal. A typical case is HTML attributes for event handlers (e.g. "onload"), in which textual data from variables should better be output to "data-*" attributes and then read from the event handler.
我该如何解决这个问题?谢谢。
【问题讨论】:
-
为什么用
spring-boot标记? -
因为这是一个 spring-boot 应用程序,我刚刚升级到 2.0.6。也许我不必标记它。认为它会有所贡献。
标签: javascript html spring spring-boot thymeleaf