eclipse-ee4j / mojarra

Mojarra, a Jakarta Faces implementation
Other
165 stars 112 forks source link

cc.attrs cannot be passed to nested composite (OWB) #5515

Open aleshi opened 1 month ago

aleshi commented 1 month ago

Describe the bug

This issue was originally discovered in Tomee10, but I was able to isolate it to mojarra+openwebbeans combination. I have parent CompositeTest.xhtml that has showSomeText attribute. And I have nested component NestedCompositeTest.xhtml with showSomeText2 attribute. I need to pass showSomeText from parent to showSomeText2 of nested component.

CompositeTest.xhtml

<ui:component
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:cc="jakarta.faces.composite"
        xmlns:ui="jakarta.faces.facelets"
        xmlns:search="jakarta.faces.composite/components" >

    <cc:interface>
        <cc:attribute name="showSomeText" default="#{true}" type="boolean" />
    </cc:interface>

    <cc:implementation>
        <p>
            CompositeTest.xhtml: showSomeText is #{cc.attrs.showSomeText}
        </p>
        <search:NestedCompositeTest showSomeText2="#{cc.attrs.showSomeText}">
        </search:NestedCompositeTest>
    </cc:implementation>
</ui:component>

NestedCompositeTest.xhtml

<ui:component
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:c="jakarta.tags.core"
        xmlns:cc="jakarta.faces.composite"
        xmlns:ui="jakarta.faces.facelets">

    <cc:interface>
        <cc:attribute name="showSomeText2" default="#{true}" type="boolean" />
    </cc:interface>
    <cc:implementation>
        <div>
            <p>
                NestedCompositeTest.xhtml: showSomeText2 is #{cc.attrs.showSomeText2}
            </p>
            <p>
                <c:if test="#{cc.attrs.showSomeText2}">
                    some text
                </c:if>
            </p>
        </div>
    </cc:implementation>
</ui:component>

The issue is that the value of showSomeText2 is always false. This assignment doesn't work: showSomeText2="#{cc.attrs.showSomeText}".

It gets even more interesting when I use the same attribute name in parent and nested components. Then I get StackOverflowError.

I was able to debug it to the point when https://github.com/apache/openwebbeans/blob/openwebbeans-4.0.2/webbeans-el22/src/main/java/org/apache/webbeans/el22/WebBeansELResolver.java is trying to get value for cc bean and instead of CompositeTest.xhtml, it takes the one that belongs to nested NestedCompositeTest.xhtml.

The same example works fine with Weld.

To Reproduce

Build war file from this repo and deploy it to tomcat: https://github.com/aleshi/mojarra_openwebbeans_issue Open: http://localhost:8080/jsf_cdi_and_ejb_war/test.jsf The page prints:

CompositeTest.xhtml: showSomeText is true

NestedCompositeTest.xhtml: showSomeText2 is false

Expected behavior

CompositeTest.xhtml: showSomeText is true

NestedCompositeTest.xhtml: showSomeText2 is true

Additional context Mojarra version: 4.0.8 Openwebbeans version: 4.0.2 Tomcat version: 10.1.31