Description
Suppose this use case:
<c:if test="...">
<testComposite:simpleComposite/>
</c:if>
<testComposite:simpleComposite/>
If c:if condition is first false and then it is true, the id for the second component will be assigned to the first one. The effect is c:if add/remove/refresh algorithm gets confused. Later if the value changes back to false, the component that is removed will be the other that is not expected. At the end the state of one component is lost.
The algoritm that generate that identifier must meet at minimal two conditions.
1. They should be unique but
2. The same ids should be generated each time the view is built for comply with c:if addition/removal algorithm.
Additionally, considering this use case:
<h:outputText value="A"/>
<ui:include src="#
"/>
<h:outputText value="C"/>
page1.xhtml:
<ui:composition>
<h:outputText value="B"/>
</ui:composition>
page2.xhtml:
<ui:composition>
<h:outputText value="B"/>
</ui:composition>
We need to ensure this condition:
3. Different ids should be generated for components in different.
To ensure two pages with the same components in this configuration can be associated with different ids, it is necessary to keep track of the facelet hierarchy.
How to solve it?
First create a "hierarchical counter" that can generate something like this:
1
2
3
4
5_1
5_2_1
5_2_2
5_2_3
5_3
The proposal I'm working on is create a counter like this:
[hierarchical counter][faceletHierarchy_prefix][tagId]
And use two hierarchical counters, one for the previous id and the other one for the component generated id.