primefaces-extensions: CombinedResourceHandler: MyFaces ParseError in Dev Mode

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?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 29 (19 by maintainers)

Commits related to this issue

Most upvoted comments

Oh sorry @volosied I think @mkomko is on JSF 4.0+

@mkomko What JSF version do you need the fix in?

@mkomko yep they have a MyFaces fix going in for your issue.

I can take another look at this. I think my fix to assign ids to child elements is reasonable to address the duplicate id exception, and I don’t see why the community would reject it.

I also removed the PostAddToViewEvent publish event in the restore view phase to avoid the duplicate scripts. However, I see duplicate scripts (css) added when i click update in the test app:

see here: image

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.