shgutman
shgutman

Reputation: 134

jsf repeat inside datatable

I'm using datatable and i get number of columns dynamically. I tried to put repeat inside like this way:

<h:dataTable  value="#{movieUserBean.sits}" var="row" 
        rowClasses="oddRows,evenRows" headerClass="header"
        styleClass="table" cellpadding="5" cellspacing="0">

      <ui:repeat  value="#{row}" var="sit">
          <h:column>
             <h:selectBooleanCheckbox   value= "#{movieUserBean.checked[sit.id]}"/>
          </h:column>
      </ui:repeat>

Which sits is a two dimensions array, my thought was that datatable should loop over the sits rows and repeat loops over every value inside every row (which is an object named Sit with get method: getId).

The problem is that I get an empty table. Seems like var "sit" is not getting value. Can the problem be the fact that datatable ignores any elements who's not in column scope?

Upvotes: 5

Views: 2589

Answers (2)

kiranutt
kiranutt

Reputation: 31

A simple solution would be

<table>
    <ui:repeat  value="#{movieUserBean.sits}" var="row">
    <tr>
        <ui:repeat  value="#{row}" var="sit">
          <td><h:selectBooleanCheckbox value= "#{movieUserBean.checked[sit.id]}"/></td>
    </ui:repeat>
    </tr>
    </ui:repeat>
</table>

If you have variable columns per row it might mess up with css styles. For example 5 columns on row one and 3 columns on row 2, how would you style them. The way i see it you want to show seats in a theater occupied with a checkbox.

You can try using ui:repeat's with ul,li or div's instead of going with the table. approach.

Upvotes: 0

Nassim MOUALEK
Nassim MOUALEK

Reputation: 4864

ui:repeat is called before the render response phase, i suggest you to use DynamicColumns of primefaces http://www.primefaces.org/showcase/ui/datatableDynamicColumns.jsf

Upvotes: 0

Related Questions