users@glassfish.java.net

Re: JSF's JspException: Component ID has already been used in the view

From: <glassfish_at_javadesktop.org>
Date: Sun, 15 Mar 2009 09:44:15 PDT

Hi,
One of the probable issue might be that you are creating dynamic html components from inside the bean without assigning any ID to it and you are trying to redirect the control the same view. Due to this, the jsf is generating the same ids for any of the dynamic component.
Try following;

Application application = FacesContext.getCurrentInstance().getApplication();
List<UIComponent> children = controlPanel.getChildren();
children.clear();
for (int i = 0; i < numControls; i++) {
        HtmlOutputText hot = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        hot.setValue(" " + (i + 1) + " ");
        hot.setId("j" + Math.abs((new Random()).nextInt()) + "_" + (i + 1));
        children.add(hot);
}

Here, the key is generating the random ID each time.

Regards,
Shailesh.
[Message sent by forum member 'shaileshaag' (shaileshaag)]

http://forums.java.net/jive/thread.jspa?messageID=337056