PrimeFacesScriptProcessor: Uncaught Synatx Error, Primefaces.settings rendered in SPAN
See original GitHub issueWhen using the PrimeFacesScriptProcessor according to the Showcase you can see in the WebDev-Console “Uncaught SyntaxError: Unexpected token ‘<’” and when inspecting the webpage you see that the “Primefaces.settings”-Part is inside of a SPAN-tag, which seems to be the cause of the error. In the Showcase itself it is not visible, but there can also not see any Primefaces.settings in the head.
When using BalusC approach, the tag gets rendered as expected but after a click or ajax request, Mojarra throws excpetion caused by duplicated id in component.
Primefaces Extension Code
private void addJS(FacesContext context, String script) { String id = UUID.randomUUID().toString(); final UIOutput js = new UIOutput(); js.setId(“js-” + id + “1”); js.setRendererType(“javax.faces.resource.Script”); final UIOutput content = new UIOutput(); content.setId(“js-” + id + “2”); content.setValue(script); js.getChildren().add(content); context.getViewRoot().addComponentResource(context, js); }
Rendered HTML:
<script type="text/javascript"><span id="js-a07c21e3-04b7-4063-b3eb-b570c6b974ee2">if(window.PrimeFaces)...</span></script>
BalusC
private void addJS(FacesContext context, String script) { UIOutput js = new UIOutput(); js.setRendererType(“javax.faces.resource.Script”); UIOutput content = new UIOutput(); content.setValue(script); js.getChildren().add(content); context.getViewRoot().addComponentResource(context, js); }
Rendered HTML:
<script type="text/javascript">if(window.PrimeFaces)...</script>
Environment:
- PF Version: 10.0.0
- JSF version: Mojarra 2.3
- Affected browsers: reproduced in Chrome and Firefox
To Reproduce Steps to reproduce the behavior:
- Include the PrimeFacesScriptProcessor according to the showcase
- Open Browser
Expected behavior No Error (and JS not encapsulated by SPAN-tag?)
Sample XHTML Trivial xhtml-page
Sample Bean No Bean necessary
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
10.0.3 is in Maven Central now…
I have verified your fix and implemented it! Thanks!