I โinheritedโ the JSF 2 application (JSF 2.2.7) in my company and ran into java.lang.IllegalStateException because the two components seem to have the same identifier.
The structure of the presentation is as follows (I extracted the appropriate code for illustration, it may contain some typos / invalid syntax when I changed some names):
<p:commandButton id="editButton" action="#{controller.prepareItem()}" update=":itemEditDlg" oncomplete="PF('itemtEditDlg').show()" /> <comp:editItemDlg id="itemEditDlg" /> <p:dialog id="anotherDlg" > <h:form id="anotherForm"> <c:forEach items="#{controller.allArgs}" var="arg" > <comp:mycomponent arg="#{arg}" /> </c:forEach> </h:form> </p:dialog>
mycomponent.xhtml is as follows:
<cc:interface> <cc:attribute name="arg" required="true" /> </cc:interface> <cc:implementation> <p:inputText id="argValue" value="#{cc.attrs.arg}" /> <p:message id="argValueMessage" for="argValue" /> </cc:implementation>
Important. The mycomponent component is also used inside editItemDlg (in the same way as in "anotherDlg"), that is, inside the dialog and forEach-loop)
If I click the editButton button, I get:
java.lang.IllegalArgumentException: Component ID anotherForm:j_idt192:argValue has already been found in the view.
Its rather strange, because "anotherDlg" in this case is not open, but, apparently, has already been visualized.
I get the following information in StackTrace (only the relevant parts are shown):
+id: j_idt192 type: javax.faces.component.UINamingContainer@399bd0dc +id: j_id2 type: javax.faces.component.UIPanel@24ad3910 +id: argValue <=============== type: org.primefaces.component.inputtext.InputText@687d5c3f +id: argValueMessage type: org.primefaces.component.message.Message@7e3361b0 +id: argValue <=============== type: org.primefaces.component.inputtext.InputText@5f52aa8a +id: argValueMessage type: org.primefaces.component.message.Message@2c3a7aea
So, somehow, these components are obtained twice, but I cannot understand why.
I went through the SO answer , but I can not determine which of the listed reasons is the problem in my case. I do not use bindings.
What I tried so far: played with setting the identifier without explanation, i.e. surrounded mycomonent, passing loop counters as component identifier, etc. without success. I think the problem cannot be resolved in mycomponent. The only workaround I found was to create a physical copy of mycomponent and link to that copy in my other form (so editItemDlg and anotherDlg do not use the same components).
Any help is appreciated