I get a duplicate ID exception when using composite components conditionally with <c:if>
I'm aware of this compile/render time issue but i have really no clue why the example below does not work.
Please have a look at the following three simple snippets
A session scoped bean named TestBean which holds a boolean value and two ajax listeners which change this value to true or false:
@Named
@SessionScoped
public class TestBean implements Serializable {
private boolean isVisible = false;
public void onSetItemVisible(AjaxBehaviorEvent e) {
this.isVisible = true;
}
public void onSetItemInvisible(AjaxBehaviorEvent e) {
this.isVisible = false;
}
public boolean isItemVisible() {
return this.isVisible;
}
}
A really simple composite component named testCmp:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface/>
<cc:implementation>
<h:outputText id="text" value="text"/>
</cc:implementation>
</html>
And a view page which allows switching between hide/show this composite component
<h:body>
<h:form id="testForm">
<c:if test="#{testBean.itemVisible}">
<test:testCmp id="test1"/>
</c:if>
<p/>
<test:testCmp id="test2"/>
<p/>
<!-- show/hide dynamic item -->
<h:commandLink value="Show Item">
<f:ajax execute="@this" listener="#{testBean.onSetItemVisible}" render="@form"/>
</h:commandLink>
<br/>
<h:commandLink value="Hide Item">
<f:ajax execute="@this" listener="#{testBean.onSetItemInvisible}" render="@form"/>
</h:commandLink>
</h:form>
</h:body>
The thing is: i get a duplicate ID Exception when i switch between show/hide. Exception says: "Component ID testForm:test2:text has already been found in the view"
It complains about 'test2' ... the component which is not conditionally added.
And when i don't use a composite component and replace it with a standard component like <h:outputText>
then anything works well.
To reproduce the error it is important, that the composite component is used two times at the same page, one times with and the other times without the condition.
After further searching i found another guy which i think has the same problem like me. But his example looks a bit more complex and is harder to reproduce. Duplicate component ID in JSF using composite component twice in view
Anybody has a clue whats going on here? My setup is JBoss EAP7 with Mojarra JSF 2.2.14 (but i tested with JSF 2.3.0-m11 too) Can someone can confirm this problem? If so i'll create a bug for the mojarray guys.