Call pushComponentToEL() in findComponent() method
This is a discussion about the currently expected behavior of the JSF spec for the UIComponent.invokeOnComponent() method. I wrote this question on stackoverflow but as it seems to be a mojarra (or spec?) bug i'll copy/paste it here
Summary
I encountered an unexpected behavior while using 2 composite component with 2 different backing component because the invokeOnComponent method do not pushComponentToEL and the ImplicitELResolver rely on the getCurrentCompositeComponent to get the value of a #{cc.xx} property.
So, should the invokeOnComponent call the pushComponentToEL before iterating over children (as it does it before invoking the call back).
This is the workaround i implemented in the overriden invokeOnComponent method of my backing bean but i'm not quite sure of the consequences.
In depths
Following is the use case i encountered with some simplified snippet to focus on the issue behind
The main facelet
Taking a simple facelet into account :
<html>
<compositeComponent:comp1>
<compositeComponent:comp2>
</html>
First composite component
The simplified code of the first custom composite component (comp1) :
<composite:interface componentType="comp1">
</composite:interface>
<composite:implementation>
<myComponentLib:myComponent />
</composite:implementation>
This one is backed by a bean we will call BACKING_COMPONENT_1
Second composite component
The simplified code of the first custom composite component (comp2) :
<composite:interface componentType="comp2">
</composite:interface>
<composite:implementation>
<p:dataTable value="#{cc.myList}" >
</p:dataTable>
</composite:implementation>
This one is backed by a bean we will call BACKING_COMPONENT_2
The scenario
The issue happens when the following scenario occurs :
encodeAllis called on the composite component 1encodeBeginis called on the composite component 1pushComponentToELis called on the composite component 1- The "CURRENT_COMPOSITE_COMPONENT_STACK" is updated
encodeAllis called on myComponent- The "myComponent" renderer needs to find a component and thus call the
invokeOnComponenton theUIViewRoot - The recursivity of the
invokeOnComponentreach theinvokeOnComponentmethod of theDataTablecomponent inside the composite component 2 - The
DataTableneed to resolve#{cc.myList}to keep visiting the tree with each row data. - The
ImplicitELResolvertry to resolve the#{cc.xxx}base. This is done using theUIComponent.getCurrentCompositeComponent()method which rely on the "CURRENT_COMPOSITE_COMPONENT_STACK" and resolve to BACKING_COMPONENT_1 (instead of the BACKING_COMPONENT_2)
The issue
In my opinion, this is some jsf spec issue that establish that the invokeOnComponent method should call the pushComponentToEL method and popComponentToEL before calling the callback if the clientId is the one searched and doesn't specify to do so when calling the invokeOnComponent method on the facetsAndChildren.
The workaround
As a workaround, I overridden the invokeOnComponent method in my composite component backing component to push and pop the component.
Asking the real questions.
Should the push and pop mechanism be used when calling invokeOnComponent method on facetsAndChildrens ?
And will this workaround can cause me some unseen issue in other cases ?