Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...