PWC6228:模板文本正文中不允许#{...} [英] PWC6228: #{...} not allowed in a template text body

查看:390
本文介绍了PWC6228:模板文本正文中不允许#{...}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JS脚本,当成功触发一个提交按钮动作时,该脚本就会被调用:

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>

但我收到错误消息:

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

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

我这样做了:

<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.

推荐答案

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

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

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

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>

如果由于尚未准备好${msg}而导致该方法不起作用(如果#{}在视图的那个位置尚不存在,则会自动创建它),那么您需要使用<h:outputText>:

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>

您只需要删除该<f:verbatim>标记,即可在其中运行JSF组件. <f:verbatim>是JSF 1.0/1.1的遗留物,自JSF 1.2起已不再需要,而自JSF 2.1起已弃用.

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.

此问题与JavaScript无关.您是从网络服务器获取错误,而不是来自网络浏览器.

This problem has nothing to do with JavaScript. You got the error from the webserver, not from the webbrowser.

这篇关于PWC6228:模板文本正文中不允许#{...}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆