Duplicate component id found in view

I was trying to add an id attribute to a custom JSF component I’ve created, it has also several other custom attributes. I’ve added an attribute id to the tld file, and defined the id attribute in the tag class like the way I do for the custom attributes. When I ran the application to test the component, the page loaded ok but when I submit it, it gave the duplicate component id in view exception.

When trying to figure out the cause of the problem, I realized that I made a mistake in my tag class because there is no need to define an id attribute, creating getters-setters and putting the variable in the attributes map. setProperties method already set the id for the component, manually putting the id attribute to the map, will threw the duplicate component id found in view exception.

When I removed everything about id in the tag class everything worked ok. Long story short, in order to add an id attribute to your custom component, the only thing you need to do is to add the id attribute tags to the tld file. I think this method will also work for the other common attributes like rendered because UIComponentTag class takes care of these attributes. 


Comments are closed.

%d bloggers like this: