question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CombinedResourceHandler: Myfaces ParseError in Dev Mode

See original GitHub issue

Describe the bug @tandraschko I have attached this reproducer: pfe-combinedresourcehandler.zip

To get the issue run the reproducer mvn clean jetty:run -Pmyfaces23 with JSF mode Development and press the “Update” button twice. On the second press you will see this in the console for the AJAX response. image

Now run the reproducer again in JSF mode Production mvn clean jetty:run -Pmyfaces23 and there is no errors or problems. I think it stems from MyFaces having an issue with duplicate ID’s for this piece of code in our handler: https://github.com/primefaces-extensions/primefaces-extensions/blob/fd939e77a2e26c765bd06efa5692fde8e3fba4b2/core/src/main/java/org/primefaces/extensions/application/PrimeFacesScriptProcessor.java#L169-L175

I used to have ID’s on there but had to be removed because of this ticket: https://github.com/primefaces-extensions/primefaces-extensions/issues/486

Any thoughts you have on this would be appreciated. It works fine in Mojarra in Development mode but I am wondering which library is doing the right thing?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mellowarecommented, Aug 28, 2021

OK @tandraschko here is what I have discovered in my research and settled on because I don’t know exactly what is wrong in MyFaces or MAY NOT BE WRONG it could be wrong in Mojarra who knows. But…

  1. We know Mojarra does not want an ID set on the JS when calling UIViewRoot.addComponentResource as reported in this ticket: https://github.com/primefaces-extensions/primefaces-extensions/issues/486
  2. MyFaces however if no ID is set automatically adds one because of this ticket: https://issues.apache.org/jira/browse/MYFACES-2775
  3. MyFaces generates the “V” kind of ID like “j_id__v_7” because this is a Script resource and from looking at the code i think its doing it correctly however its reporting DuplicateId when it should be replacing the old “j_id__v_7” because it should be finding that component with the same name.

The solution I settled on was to set an ID for MyFaces and leave it blank for Mojarra. I have tested and this now works for all 4 use cases MyFaces and Mojarra and Development mode and Production Mode.

private void addJS(final FacesContext context, final String script) {
        final UIOutput js = new UIOutput();
        js.setRendererType("javax.faces.resource.Script");
        // https://github.com/primefaces-extensions/primefaces-extensions/issues/486
        // https://github.com/primefaces-extensions/primefaces-extensions/issues/517
        // MyFaces needs ID set to prevent duplicate ID check in Dev mode, Mojarra does not
        final PrimeEnvironment environment = PrimeApplicationContext.getCurrentInstance(context).getEnvironment();
        if (!environment.isMojarra()) {
            js.setId("primfaces-script-processor");
        }
        final UIOutput content = new UIOutput();
        content.setValue(script);
        js.getChildren().add(content);
        context.getViewRoot().addComponentResource(context, js);
    }

cc @Phipsee since you reported the issues with Mojarra I wanted you to see this ticket.

0reactions
mellowarecommented, Aug 26, 2021

Before when I was manually setting an ID both Mojarra and Myfaces turn it into a SPAN like…

<script type="text/javascript"><span id="js-12345">if(window.PrimeFaces)...</span></script>

So I had to remove the ID’s from this to let it generate the script properly without the SPAN

<script type="text/javascript">if(window.PrimeFaces)...</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

MyFaces continues to run in DEV mode after project stage ...
I had setup JRebel on this project and it turns on facelet DEVELOPMENT mode. http://zeroturnaround.com/software/jrebel/features/frameworks/.
Read more >
CombinedResourceHandler - OmniFaces Showcase
This ResourceHandler implementation will remove all separate script and stylesheet resources which have the target attribute set to "head" from the ...
Read more >
yandex-big-data-analysis/Week2-Hive-Assignment-2-DML
Logging initialized using configuration in jar:file:/usr/local/apache-hive-1.1.0-bin/lib/hive-common-1.1.0.jar!/hive-log4j.properties Added ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found