Search code examples
jsftomahawk

How to loop through list of items and present it in a fixed amount of columns


I want to loop throw list of items and to present them in away that each row has 3 columns

Using this code,

<t:dataTable var="itemInfo" value="#{itemBean.itemList}">
    <h:column>
        <h:outputText value="#{itemInfo.name}" />
    </h:column>
</t:dataTable>

I'm able to present it on one column, but how can I present it on 3 columns?

For example, if I have 9 items A B C D E F G H I, then it should look like this:

A B C
D E F
G H I

Solution

  • You can use panelgrid with c:forEach like this:

    <h:panelGrid columns="3">
      <c:forEach items="#{itemBean.itemList}”" var="itemInfo">
        <h:outputText value="${itemInfo.name}"/>
      </c:forEach>
    </h:panelGrid>
    

    or you can use primefaces dataGrid or sth like that: http://www.primefaces.org/showcase/ui/datagrid.jsf