PWC6228:模板文本正文中不允许使用#{...}

发布于 2024-12-17 17:37:00 字数 693 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泛滥成性 2024-12-24 17:37:01

PWC6228:模板文本正文中不允许使用 #{...}。

显然您正在使用旧版 JSP(X),而不是其后继 Facelets。 JSP(X) 不支持模板文本中的延迟 EL #{}。它仅支持模板文本中的标准 EL ${}(模板文本意味着外部标签/JSF 组件):

<script type="text/javascript">alert('${msg.report_alert_text}');</script>

如果这不起作用,因为 ${msg} 未被使用 则 #{} 将自动创建它),那么您需要

<script type="text/javascript">alert('<h:outputText value="#{msg.report_alert_text}" />');</script>

准备好(如果在视图的该点尚不存在, 只需要删除它 标记以使 JSF 组件在那里运行。 是 JSF 1.0/1.1 的遗留物,自 JSF 1.2 起不再需要,并且自 JSF 2.1 起已弃用。

这个问题与 JavaScript 无关。您从网络服务器而不是网络浏览器收到错误。

PWC6228: #{...} not allowed in a template text body.

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):

<script type="text/javascript">alert('${msg.report_alert_text}');</script>

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:

<script type="text/javascript">alert('<h:outputText value="#{msg.report_alert_text}" />');</script>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文