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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
lamostreta
  • 2,359
  • 7
  • 44
  • 61

1 Answers1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I removed verbatim tag. I tried first and then . But both cases did not work.. – lamostreta Nov 21 '11 at 14:59
  • 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. – lamostreta Nov 21 '11 at 15:01
  • 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. – lamostreta Nov 21 '11 at 15:02
  • 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. – BalusC Nov 21 '11 at 15:04
  • I couldn't catch any JS error. All I get is " GET https://192.168.0.165:81/lrms/theme/com/sun/webu...eme4_2-080320/javascript/widget/calendarField.js GET https://192.168.0.165:81/lrms/theme/com/sun/webui/jsf/suntheme4_2-080320/javascript/widget/calendarField.js 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. – lamostreta Nov 22 '11 at 07:33
  • There was a problem with the backing bean. Now that I corrected it, it works perfect! Thanks a lot. – lamostreta Nov 23 '11 at 14:18