JspException: Component ID has already been used in the view

Hello,

We're developing a large JSF-based app with custom .tag on glassfishV1/AS9.0.1 and our team is having an extremely hard time dealing with JspException: Component ID has already been used in the view.

They seem to pop-up randomly and even if we go through the trouble of setting an id for every single JSF component on that page, sometimes we still get this error...

#|2007-06-18T12:32:11.964-0700|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.container.web|_ThreadID=18;_ThreadName=httpWorkerThread-8181-0;_RequestID=fd866d2a-2e39-42d5-b5eb-8ebd9e0de0fb;|ApplicationDispatcher.log: ApplicationDispatcher[] Servlet.service() for servlet jsp threw exception javax.servlet.jsp.JspException: Component ID 'moduleinviteFriends' has already been used in the view.

See below for the view up to the point of the detected error.

+id: j_id_id11

type: javax.faces.component.UIViewRoot@141c44d

+id: j_id0

type: javax.faces.component.html.HtmlOutputText@bedc80

+id: javascriptInclude

type: javax.faces.component.UINamingContainer@7e7394

+id: j_id1

type: javax.faces.component.html.HtmlOutputText@1d6105e

Sometimes, if we remove all ids then the error goes away... Other times, just playing around with adding/removing comments can make the error come or go away! It's very unpredictable and often jeopardize our schedules as it can take many hours to fix just one of those.

I was wondering if it's a pain many JSF developers go through or if we do something specific to deserve that.

Is anyone struggling with those errors too?

Are there best practices on how to avoid and/or fix those?

Thank you,

[1714 byte] By [bouteilla] at [2007-11-27 8:10:28]
# 1
In general, unless you have a specific reason to include it, do not use the id attribute.
RaymondDeCampoa at 2007-7-12 19:54:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Lets just review a few common things, I have not used glassfish so I cannot speak for how it is detecting componentId reuse.

1. In JSF there is a concept called a naming container. Everytime you specify an id it must be UNIQUE within a naming container. If you do not specify an id, JSF will automatically create a new (usually sequential) id for each component. A naming container sets a prefix if you will that all children will inherit and have prepended to their ids.

2. Most of the newer JSF implementations will look for component id collisions. Some will just emit an error others will stop, obviously glassfish throws and error.

3. The most common problem with duplicate ids is someone is using a JSTL tag that loops over a component or includes another jsp with component having defined ids. This will duplicate the id causing said issue.

Its hard to say whats up if you don't provide source. In your stack I see a javaScriptInclude (potential errors), we see a naming container (thinking this may be h:form), an output text and them boom.

smurray_eriea at 2007-7-12 19:54:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...