Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create table columns dynamically in JSF

I'm working on dashboard application where I have to retrieve a set of records and display in dynamic tables boxes. Page frame length is fixed. now of columns and rows can be initialized. It should look like this sample:

enter image description here

Currently I'm using data table to display but it prints all the data in one column. How would I change my code to above pattern?

<o:dataTable id="tabBlSearch" var="item"
     onkeyup="handleLeftRightArrowOnDataTable('frmDashBoard:tabBlSearch')"
     value="#{bLDashBoardAction.listBondLoc}">
  <o:column style="width: 20px;">
    <h:outputText value="#{item.awb}" />
  </o:column>
</o:dataTable>
like image 668
Bernad Ali Avatar asked Jul 01 '12 08:07

Bernad Ali


1 Answers

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>
like image 128
BalusC Avatar answered Sep 27 '22 21:09

BalusC