Hello all,
I have an annoying problem with Trinidad and 'duplicate' ids. It doesn't
seem to affect functionality, but if released into production, it would
end up generating boatloads of useless log entries. Alternatively, it
seems rather self defeating to try and add custom log settings to
selectively ignore these warnings.
I'm converting an application away from Tomahawk and into Trinidad and I
get repeated warnings of the form:
Mar 28, 2008 2:54:27 PM
org.apache.myfaces.trinidadinternal.io.DebugResponseWriter _logDuplicateId
WARNING: The id "mainForm:_myt379" is used more than once.
Most of the components on this page are created programmatically, so it
was easy to dump out details allowing me to correlate the id's in
question with component types. Based on a bit of Googling, I expected to
find that they related to labels or message components, but instead
found that they all related to org.apache.myfaces.HtmlPanelTab instances.
Is there something about how HtmlPanelTab instances are created that
differs from other components? Any idea what I have to do to get rid of
all the warnings?
The code which creates these components is very simple:
public static HtmlPanelTab createTab(final String tabText)
{
HtmlPanelTab tab = (HtmlPanelTab)
createComponent(HtmlPanelTab.COMPONENT_TYPE);
tab.setStyle("width=100%;");
tab.setStyleClass("panel");
tab.setLabel(tabText);
return tab;
}
private static UIComponent createComponent(String componentType)
{
Application app =
FacesContext.getCurrentInstance().getApplication();
UIComponent comp = app.createComponent(componentType);
comp.setId( generateId() ); // ensure that every component has
some id specified
System.out.println( "created " + componentType + ". ID: " +
comp.getId() );
return comp;
}
private static int s_Id = 0;
public synchronized static String generateId()
{
if ( s_Id == (Integer.MAX_VALUE-1) )
s_Id = 0; // presumably at this point it's OK to start over
s_Id++;
StringBuffer b = new StringBuffer("_myt");
b.append(String.valueOf(s_Id));
return b.toString();
}
The resulting trace from the sysout above and the error console when
viewing the page is:
created org.apache.myfaces.HtmlPanelTab. ID: _myt379
...
Mar 28, 2008 2:54:27 PM
org.apache.myfaces.trinidadinternal.io.DebugResponseWriter _logDuplicateId
WARNING: The id "mainForm:_myt379" is used more than once.
Any ideas appreciated. Thanks
--
Shane