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

1

1

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.

Idea answered 21/11, 2011 at 14:44 Comment(0)
C
2

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.

Cheek answered 21/11, 2011 at 14:47 Comment(6)
I removed verbatim tag. I tried <script type="text/javascript">alert('${msg.report_alert_text}');</script> first and then <script type="text/javascript">alert('<h:outputText value="#{msg.report_alert_text}" />');</script> . But both cases did not work..Idea
also I just added JS tag for info. But SO is listing the tags alphabetically and it looks like the most important tag is JS, but it is just related.Idea
sorry, it did not give any alert box. It just created the new report. It looks like it did not reach the panel group at all.Idea
Do you get any JS errors? Open the browser's JS console (or the one of whatever webdeveloper browser plugin you're using). What do you see in the generated HTML output? Open page in browser, rightclick and view source.Cheek
I couldn't catch any JS error. All I get is " GET 192.168.0.165:81/lrms/theme/com/sun/webu...eme4_2-080320/… GET 192.168.0.165:81/lrms/theme/com/sun/webui/jsf/… 200 OK 49ms Error: createWidget has null props bootstrap.js (line 22) Error: createWidget has null props bootstrap.js (line 22)" which is irrelevant, I think.Idea
There was a problem with the backing bean. Now that I corrected it, it works perfect! Thanks a lot.Idea

© 2022 - 2024 — McMap. All rights reserved.