0

I have a primefaces datatable and 2 panelgrid in a column of this datatable. Second panelgrid works properly but I need to render first panelgrid one single time only. I added my code below. How can I render first panelgrid one time per var?

<p:dataTable value="#{bean.list}" var="var">
    <p:column style="width: 60px;" groupRow="true">
        <!--data-->
    </p:column>                            
    <p:column>
        <p:panelGrid columns="4">   
            <!--data-->
        </p:panelGrid>
        <p:panelGrid columns="4" rendered="#{!rendered}">
            <!--data-->
        </p:panelGrid>
    </p:column>
</p:dataTable>
Selaron
  • 6,105
  • 4
  • 31
  • 39
İlkay Gunel
  • 712
  • 2
  • 11
  • 24

1 Answers1

1

Break down your problem and generalize it. Your title e.g. is already in two ways (or three) too specific.

How to render a panelgrid one single time in datatable with JSF and Primefaces?

  • A 'panelgrid' could be changed into 'a component'
  • 'one single time' could be changed into 'conditionally'

And the 'single time' is not specific enough like I tried to get clear in my comment. You effectively want to render it (or not) based on the row number or index.

So the better title (and question) would have been:

How do I render a component just in the first row in a p:datatable

But...

For conditionally rendering a component you sort of already know that you need to use the rendered attribute. And questions for conditionally displaying JSF components already exist.

And if you are aware that you sort of need the row number or index (in JSF or a p:datatable) you could have created a search for that to in a search engine and you would have found Display p:dataTable Row Numbers which shows the existence of the rowIndexVar attribute. In addition to this, or rather before this, just using code completion in an IDE or using the PrimeFaces documentation would have given an indication of the existence of the rowIndexVar attribute as well.

Combining all this would not have been too difficult and would have given you the following working code:

<p:dataTable value="#{bean.list}" var="var" rowIndexVar="index">
    <p:column style="width: 60px;" groupRow="true">
        <!--data-->
    </p:column>                            
    <p:column>
        <p:panelGrid columns="4" rendered="#{index == 0}>   
            <!--data-->
        </p:panelGrid>
        <p:panelGrid columns="4" rendered="#{!rendered}">
            <!--data-->
        </p:panelGrid>
    </p:column>
</p:dataTable>

So generalize, simplify, rtfm... it always helps...

Kukeltje
  • 12,223
  • 4
  • 24
  • 47