0

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

Krishna
  • 609
  • 1
  • 6
  • 17

1 Answers1

3

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>
stg
  • 2,757
  • 2
  • 28
  • 55
  • should work, but why use `c:forEach` when you have `ui:repeat`? – tt_emrah Apr 22 '15 at 21:21
  • Thank U all, I tried this but not fulfilling my requirement. Actually I have to render radios in place of these 1,2,3... n. but if I did this based on c:forEach, one radio button itself got split into 3 columns (means 1 radio in a row divided by 3 columns). Whereas I need to render 3 radio buttons in a row (means in 3 columns) – Krishna Apr 23 '15 at 03:13
  • 3
    @tt_dev ui:repeat itself is a component, while c:foreach is a taghandler. In this case here, if you use ui:repeat instead of c:foreach, then there is exactly one child for the panelgrid (the ui:repeat itself). Thus it would render everything in the first column of your grid. However, you could of course use ui:repeat instead but then you have to create the grid manually. – stg Apr 23 '15 at 05:27
  • 1
    @Krishnan the answer completely fulfils the requirements you mentioned in the original question. If you have different requirements, then clarify your quesiton in the original post. e.g. I do not understand what you mean by "a button got split into 3 columns"? – stg Apr 23 '15 at 05:31
  • @stg as u requested, my actual requirement updated in original post. Thanks in advance – Krishna Apr 25 '15 at 12:58
  • @stg I tried c:forEach like this, ` ` – Krishna Apr 25 '15 at 13:15
  • @stg, This is the html output I got for c:forEach, ` ... ... ...
    `
    – Krishna Apr 25 '15 at 13:16
  • @stg After some R&D, I found the reason why the radio buttons got displayed in 3 columns. It was due to that separate tag used for displaying item description. After modifying radio button like `#{item.desc}"` I found, it is fulfilling my requirement ;-)... Thanks yar... – Krishna Apr 25 '15 at 14:20