PWC6228:模板文本正文中不允许使用#{...}
我有一个 JS 脚本,当提交按钮操作成功触发时会调用该脚本:
<h:panelGroup rendered="#{user$webreports$webfilteroverview.submitted}">
<f:verbatim>
<script type="text/javascript">alert('Done!');</script>
</f:verbatim>
</h:panelGroup>
上面的代码工作完美。我想要做的是从资源包中获取警报框文本:
<script type="text/javascript">alert('#{msg.report_alert_text}');</script>
但我收到错误:
PWC6228:模板文本正文中不允许使用 #{...}。
我这样做了:
<h:commandbutton onClick="alert('#{msg.report_alert_text}');"/>
而且效果很好。我不明白为什么上面的代码不起作用。可以这样做吗?如果是的话,上面的代码有什么问题吗?提前致谢。
I have a JS script which is called when a submit button action is fired successfully:
<h:panelGroup rendered="#{user$webreports$webfilteroverview.submitted}">
<f:verbatim>
<script type="text/javascript">alert('Done!');</script>
</f:verbatim>
</h:panelGroup>
the above code works perfect. What I want to do is to get the alert box text from resource bundle:
<script type="text/javascript">alert('#{msg.report_alert_text}');</script>
but I get error:
PWC6228: #{...} not allowed in a template text body.
I did this:
<h:commandbutton onClick="alert('#{msg.report_alert_text}');"/>
and it was working fine. I don't understand why the above code doesn't work. Is it possible to do this? If yes, what is wrong with the above code? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然您正在使用旧版 JSP(X),而不是其后继 Facelets。 JSP(X) 不支持模板文本中的延迟 EL
#{}
。它仅支持模板文本中的标准 EL${}
(模板文本意味着外部标签/JSF 组件):如果这不起作用,因为
${msg}
未被使用 则#{}
将自动创建它),那么您需要
:准备好(如果在视图的该点尚不存在, 只需要删除它
标记以使 JSF 组件在那里运行。
是 JSF 1.0/1.1 的遗留物,自 JSF 1.2 起不再需要,并且自 JSF 2.1 起已弃用。这个问题与 JavaScript 无关。您从网络服务器而不是网络浏览器收到错误。
You're apparently using the legacy JSP(X) instead of its successor Facelets. Deferred EL
#{}
in template text is not supported by JSP(X). It only supports standard EL${}
in template text (template text means outside tags / JSF components):If that doesn't work because
${msg}
is not been prepared (the#{}
will namely autocreate it if it does not exist yet at that point of the view), then you need<h:outputText>
instead:You'll only need to remove that
<f:verbatim>
tag in order to get JSF components to run there. The<f:verbatim>
is a leftover from JSF 1.0/1.1 and not necessary anymore since JSF 1.2 and deprecated since JSF 2.1.This problem has nothing to do with JavaScript. You got the error from the webserver, not from the webbrowser.