h:dataTable binding =>重复的ID [英] h:dataTable binding => duplicate ID

查看:143
本文介绍了h:dataTable binding =>重复的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用HtmlDataTable查看数据库中的数据时遇到问题。

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.

它显示正确并且经过多次刷新(没有在dtb或其他东西中移动),例如有6列而不是3列和应用程序(有时)变得不稳定。
从那时起我无法使用表,因为它报告组件的重复ID..

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"..

简单示例(来源: http://balusc.blogspot.com/2006/06/using-datatables.html ):

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> 

和java.class

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;  
} 

错误信息:

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)  

其次是组件树。
我认为代码中没有任何重复,但dataTable创建了一个新列,之后它真的重复了

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.

你遇到过这种问题吗?

感谢您的建议

推荐答案

如果bean是会话作用域而不是请求作用域,并且您在多个视图之间共享此bean,则会发生这种情况。最好的方法是在请求范围内保留组件绑定到的bean。

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.

作为替代方案,您也可以使用 DataModel 作为值,而不是将表绑定到 HtmlDataTable 如果功能要求是获取当前选定的行。

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.

这篇关于h:dataTable binding =&gt;重复的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆