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" />
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…