I have a problem with duplicated ids in my JSF app. I've read in this post that one of the possible solutions is to use Naming Container. Can you give me some example how to use the Naming Container to avoid duplicated ids problem? I use Facelets.
This is what worked for me using JSF1.2 and facelets:
I discovered that neither <ui:composition>
nor <ui:component>
is actually a naming container, so using the same component more than once in the same form would fail with a duplicate ID exception. This seems like a bad design, as the whole point of components is re-usability. To get around this problem I include a <f:subview>
within each component and set the id on it as a parameter of my component tag:
myComponent.xhtml:
<ui:component>
<f:subview id="#{id}">
....component code
</f:subview>
</ui:component>
and the using it on other pages is simple (after setting up taglib.xml and web.xml correctly):
<myTagLib:myComponent id="myCompA" />