JSF 2.3 Facet in Composite Component with wrong ID

Viewed 423

I have the following simple code in a composite component (using Mojarra 2.3.9 / Primefaces 7):

<composite:implementation>
    <h:form id="form">
            <composite:insertChildren />

            <ui:fragment rendered="#{!empty cc.facets.actions}">
                <div class="actions">
                    <composite:renderFacet name="actions" />
                </div>
            </ui:fragment>
        </div>
    </h:form>
</composite:implementation>

And the following part is used in a page, trying to fill the composite form with life:

<cc:compForm id="mySpecialForm">
    <f:facet name="actions">
        <p:commandButton
                id="myBtn"
                value="Submit"
                process="@form"
                update="@form">
        </p:commandButton>
    </f:facet>
</cc:compForm>

The form and all the children are rendered correctly and working quite well. But the button in the renderFacet block has - in my opinion - a wrong client ID, because instead of:

mySpecialForm:form:myBtn

the button only gets the following clientId:

mySpecialForm:myBtn

This leads to an error rendering the page:

Cannot find component for expression "@form" referenced from "mySpecialForm:myBtn".: org.primefaces.expression.ComponentNotFoundException: Cannot find component for expression "@form" referenced from "mySpecialForm:myBtn".

Am i doing something wrong or is this a bug in JSF/Primefaces? I also tried to configure the componentType to an @FacesComponent extending from UIForm, but in this case no form will be rendered at all.

Update 1:

I tried to create a "minimal, reproducible example (reprex)" like mentioned by Kukeltje. All what is needed are those 2 Parts in a web application (both files under resources):

cc/compForm.xhtml:

<html
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:composite="http://xmlns.jcp.org/jsf/composite">

    <composite:interface name="compForm" displayName="A composite form">
        <composite:facet name="actions" />
    </composite:interface>

    <composite:implementation>
        <h:form id="form">
            <composite:insertChildren />
            <composite:renderFacet name="actions" />
        </h:form>
    </composite:implementation>
</html>

compFormTest.xhtml:

<html
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        xmlns:cc="http://xmlns.jcp.org/jsf/composite/cc">
    <cc:compForm id="mySpecialForm">
        <h:inputText id="inputParam" value="" />

        <f:facet name="actions">
            <h:commandButton id="myBtn" value="Test" />
        </f:facet>
    </cc:compForm>
</html>

All todo is call the .xhtml page: http:localhost/YOUR_APP/compFormTest.xhtml.

After using it (at least with Mojarra JSF implementation), the input field has the following correct client ID mySpecialForm:form:inputParam. But the command button retrieves another client ID outside the form: mySpecialForm:myBtn, what is a bug from my point of view, regarding the JSF VDL: " ... will be rendered at this point in the composite component VDL view.".

But as i downstriped the example files, it is clearly not a primefaces problem, because the wrong client ID is also included, if using the standard h:commandButton component.

Perhaps someone can use the mentioned 2 files above in a MyFaces environment to check if the behaviour differs or is the same?

Or has someone a workaround in mind? Using an additional @FacesComponent and moving the button from facet to the right spot under the form leads to the following "funny" duplicate ID error:

"Cannot add the same component twice: mySpecialForm:form:myBtn" (at least the client ID was what i expected in the first place)

0 Answers
Related