JohnSmith2
JohnSmith2

Reputation: 47

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

Upvotes: 0

Views: 5320

Answers (2)

stg
stg

Reputation: 2797

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

Upvotes: 1

Grim
Grim

Reputation: 2040

Use panelgrid instead of datatable.

Regards

Upvotes: 0

Related Questions