mojarra icon indicating copy to clipboard operation
mojarra copied to clipboard

Call pushComponentToEL() in findComponent() method

Open xqvier opened this issue 8 years ago • 0 comments

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 :

  1. encodeAll is called on the composite component 1
  2. encodeBegin is called on the composite component 1
  3. pushComponentToEL is called on the composite component 1
  4. The "CURRENT_COMPOSITE_COMPONENT_STACK" is updated
  5. encodeAll is called on myComponent
  6. The "myComponent" renderer needs to find a component and thus call the invokeOnComponent on the UIViewRoot
  7. The recursivity of the invokeOnComponent reach the invokeOnComponent method of the DataTable component inside the composite component 2
  8. The DataTable need to resolve #{cc.myList} to keep visiting the tree with each row data.
  9. The ImplicitELResolver try to resolve the #{cc.xxx} base. This is done using the UIComponent.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 ?

xqvier avatar Feb 15 '18 19:02 xqvier