Create table columns dynamically in JSF

You can achieve this with standard JSF components using a <h:panelGrid> wherein <c:forEach> is been used to generate the cells during the view build time. The <ui:repeat> won’t work as that runs during view render time.

<h:panelGrid columns="5">
    <c:forEach items="#{bean.items}" var="item">
        <h:panelGroup>
            <h:outputText value="#{item.value}" />
        </h:panelGroup>
    </c:forEach>
</h:panelGrid>

As to component libraries, I don’t see anything in OpenFaces’ showcase, but PrimeFaces has a <p:dataGrid> for exactly this purpose, even with pagination support.

<p:dataGrid columns="5" value="#{bean.items}" var="item">
    <p:column>
        <h:outputText value="#{item.value}" />
    </p:column>
</p:dataGrid>

Leave a Comment