Search code examples
jsfdatatableuirepeat

Customized rendering of elements in datatable


I have n elements in an arraylist, I want to display all those in a table of (n/3) X 3 format (by single iteration) with respective number of radio buttons like,

<table>
<tbody>
<tr>
  <td><input type="radio" name="category1" id="category1" value="1"></td>
  <td><input type="radio" name="category1" id="category1" value="2"></td>
  <td><input type="radio" name="category1" id="category1" value="3"></td>
</tr>
<tr>
  <td><input type="radio" name="category1" id="category1" value="4"></td>
  <td><input type="radio" name="category1" id="category1" value="5"></td>
  <td><input type="radio" name="category1" id="category1" value="6"></td>
</tr>
...
<tr>
  <td><input type="radio" name="category1" id="category1" value="n"></td>
  <td></td>
  <td></td>
</tr>
</tbody>
</table>

Please help


Solution

  • You may just use h:panelGrid and c:forEach

    <h:panelGrid columns="3">
        <c:forEach items="#{myBean.list}"  var="item">
            <h:outputText value="#{item}" />
        </c:forEach>
    </h:panelGrid>
    

    It will render a <table />

    <tbody>
        <tr>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
        <tr>
            <td>4</td>
            <td>5</td>
            <td>6</td>
        </tr>
        ...
    </tbody>