JavaServer Faces : java.lang.IllegalStateException: Component ID has already been found in the view. How resolve ?

Firstly you really need validate your code, because this error says that you have two components with the same ID . Some times don’t have any  duplicated id in my file, so what I can do now ? How resolve this problem?

The best way and the first tip is: You need only set value for id attributes where is really necessary. Why ?

The framework will auto-generate a unique values for ids, but it happens only when you don’t set any value in id attribute .

To  know more you can look in the documentation of the responsible method for do this :

http://docs.oracle.com/javaee/5/api/javax/faces/component/UIComponent.html#getClientId%28javax.faces.context.FacesContext%29

When I need use the ID and Name attributes ?

In the big part of the cases, it’s only happens if you need call the component. One example of this is when you want update some component after some event.

Example:

<p:selectOneMenu  style="width:150px"
                 value="#{myController.objectSelected}"
                 converter="genericEntityConverter">

    <f:selectItems value="#{myController.takeAllObjects()}"
                   var="object"
                   itemLabel="#{object.name}"
                   itemValue="${object}">
    </f:selectItems>
    <p:ajax event="change" process="@this" update="otherPanel"/>
</p:selectOneMenu>
<h:panelGroup id="otherPanel">
{...}
</h:panelGroup>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s