GeeCON Prague 2014*
The moose likes JSF and the fly likes Duplicate Id across my Views? How come? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Duplicate Id across my Views? How come?" Watch "Duplicate Id across my Views? How come?" New topic
Author

Duplicate Id across my Views? How come?

Marcos Silvestri
Ranch Hand

Joined: Dec 06, 2009
Posts: 62

Hello folks!

I'd like you please to look at the attachment, an image that displays the Search Results tab of the Netbeans IDE, informing all occurrences of the Id "pnlAgendaUsuario".

I'm getting the error message

java.lang.IllegalStateException: duplicate Id for a component pnlAgendaUsuario

from my View, but there's something that makes no sense at all to me:

As the attached picture displays, the Id "pnlAgendaUsuario" is declared only once in the whole project. If that's the case, how can I receive an error message informing that such an Id is duplicated???

All the other references to "pnlAgendaUsuario" are just requests for its use, not declarations.

Has anyone ever undergone the same experience or have something in mind to suggest?

Thanks in advance!



[Thumbnail for Id duplicate error.png]



DJ aspirant, Engineering undergraduate, Tokusatsus addicted, fond of English language and Asia's, Buddhist, blogger, etc. I'll need to insert all these attributes in a Java class and manage to create methods for handling my overwhelming life
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Maybe is declared only once, but the fragment that declares it can be used in more than one place.

Check for codes like "include" that are adding the same code more than once.


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Marcos Silvestri
Ranch Hand

Joined: Dec 06, 2009
Posts: 62

Hello Hebert and everybody!

I've talked to a senior co-worker and the explained something that definitely solved the problem. As you said, it had to do with it, though not declaring the Id more than once, the same was being used twice in my environment.

Through the use of Facelets, our pages are a composite of minor ones through the use of tags include (ui:include). One of my Views were being included twice, once globally, viewable by all Views, and again, within a particular View. By removing the latter, the system worked smoothly.

In the end, it had no apparent direct relation with that Id "pnlAgendaUsuario", though that could be implied and not immediately noticeable.

In sum, if any of you run against a similar problem, check to see if there are multiple references to the same Views through the tag include (ui:include). This a possible solution!

Another possible solution would be isolating Ids within (a4j:form) tags, so that their names are transformed into a composite of the type "formName:Id" instead of "Id" only, defining a kind of namespace for the Ids. Without it, at run-rime only, it could be possible that the same "Id" could be called more than once when assembling the page, then the duplication happens, what would not happen by defining composite names by placing those Ids within form tags.

That's all from me, thanks!!!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16095
    
  21

Marcos Silvestri wrote:Hello Hebert and everybody!
Another possible solution would be isolating Ids within (a4j:form) tags, so that their names are transformed into a composite of the type "formName:Id" instead of "Id" only, defining a kind of namespace for the Ids. Without it, at run-rime only, it could be possible that the same "Id" could be called more than once when assembling the page, then the duplication happens, what would not happen by defining composite names by placing those Ids within form tags.
That's all from me, thanks!!!


That's because the "h:form" tag is what is known as a naming container. IDs within a naming container are considered unique, so long as they are defined only once in in the container.

Another naming container is the h:dataTable. In the dataTable, even though a row may be repeated, each ID is unique, because the generated absolute name contains the row number as part of the ID.


Customer surveys are for companies who didn't pay proper attention to begin with.
Marcos Silvestri
Ranch Hand

Joined: Dec 06, 2009
Posts: 62

I wanted to leave possible resolutions to this problem for whoever comes across it and gets to the web in search of it, and you added more to it, Tim. Good job, now it's a mini-knowledge base about it!!!

Regards from Brazil!
 
GeeCON Prague 2014
 
subject: Duplicate Id across my Views? How come?