0

I am using JSF 2.0 in my project. I am struck with the implementation. Currently I am implementing a composite component for data table / tree table. I am creating a generic component for datatable and treetable. User using this composite component has to pass a boolean to say display data in tree table or data table.

<cc:attribute name="treeMode" default="false" type="java.lang.Boolean"/>

<p:dataTable rendered="#{cc.attrs.treeMode == 'false'} id="#{cc.attrs.id} value=".../>
<p:treeTable rendered="#{cc.attrs.treeMode == 'true'}" id="#{cc.attrs.id} value=".../>

If I need datatable, i use

  <nav:navDataGrid
     id="testTable"
     treeMode="true"
     databean="testBean" .../>

I am also passing ID attribute. But my problem is when use the composite component using the above code I am getting

Component ID testTable:testTable has already been found in the view.  

I think that is because it is rendering both data table and tree table. When I pass treeMode=tree, why datatable is getting rendered ? How can I resolve this ? Is there any other option other that creating one more composite component for TreeTable ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Lolly
  • 34,250
  • 42
  • 115
  • 150

1 Answers1

1

Remember that in JSF, the component model is built several steps in the life cycle before the response is prepared and rendered. Therefore, even though both of those components will never be rendered at the same time, they each need a different id.

Ian McLaird
  • 5,507
  • 2
  • 22
  • 31
  • Indeed. Related reading about "view build time" versus "view render time": http://stackoverflow.com/a/3343681 and http://stackoverflow.com/a/14917453 – BalusC Jan 20 '14 at 15:29