Reputation: 3479
I have a problem using HtmlDataTable for viewing data from database.
When I create component, the table has sometimes (not always) twice number of columns.
It is shown correctly and after several refreshes (without move in dtb or something) there is for example 6 columns instead of 3 and application (sometimes) become unstable. Since this time I can't work with table because it reports "duplicate Id for a component"..
Simple example (source: http://balusc.blogspot.com/2006/06/using-datatables.html):
<h:form id="bde">
<h:dataTable id="tbl"
binding="#{myBDE.dataTable}"
value="#{myBDE.dataList}"
var="bdeItem">
<h:column>
<f:facet name="header">
<h:outputText value="S" />
</f:facet>
<h:outputText value="#{bdeItem.s}" rendered="#{!myBDE.editModeRow}"/>
<h:inputText value="#{bdeItem.s}" rendered="#{myBDE.editModeRow}" required="true" size="3"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="ID" />
</f:facet>
<h:outputText value="#{bdeItem.id}"/>
</h:column>
</h:dataTable>
</h:form>
And java.class
protected HtmlDataTable dataTable;
public void setDataTable(HtmlDataTable dataTable)
{
this.dataTable = dataTable;
}
public HtmlDataTable getDataTable()
{
if (dataTable == null)
{
dataTable = new HtmlDataTable();
dataTable.setRows(DEFAULT_TABLE_ROWS);
}
return dataTable;
}
And the Error message:
javax.servlet.ServletException: Component ID j_idt92:bde:tbl:j_idt129 has already been found in the view.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:422)
root cause
java.lang.IllegalStateException: Component ID j_idt92:bde2:tbl:j_idt129 has already been found in the view.
com.sun.faces.util.Util.checkIdUniqueness(Util.java:821)
com.sun.faces.util.Util.checkIdUniqueness(Util.java:805)
com.sun.faces.util.Util.checkIdUniqueness(Util.java:805)
com.sun.faces.util.Util.checkIdUniqueness(Util.java:805)
com.sun.faces.util.Util.checkIdUniqueness(Util.java:805)
com.sun.faces.util.Util.checkIdUniqueness(Util.java:805)
com.sun.faces.application.view.StateManagementStrategyImpl.saveView(StateManagementStrategyImpl.java:144)
com.sun.faces.application.StateManagerImpl.saveView(StateManagerImpl.java:133)
com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:418)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:410)
Followed by tree of components. I thing there's nothing duplicated in code, but dataTable create a new columns and after that it's really duplicated
I have two working similar modules, and the third doesn´t work.
Have you ever met this kind of problem?
Thanks for advice
Upvotes: 3
Views: 7001
Reputation: 1108632
This can happen if the bean is session scoped instead of request scoped and you're sharing this bean among multiple views. Best is to keep the bean to which the component is been bound in the request scope.
As an alternative, you can also use DataModel
as value instead of binding the table to HtmlDataTable
if the functional requirement is to get the currently selected row.
Upvotes: 6