0 Replies Latest reply on May 17, 2007 12:42 PM by aoifejk

    Dynamically populating DataTable

    aoifejk

      I'm trying to create and populate a dataTable dynamically. By this I mean that we don't know when the JSP is being written the number of columns that will be in dataTable or how many rows. I suspect this can be done in Java code but I need to see if it's possible to do without introducing richFaces dependency in Java.
      What I did was write my backing bean so that it returns a java.util.List of column headers which I use c:forEach to iterate through and create column headers. That's works fine. The 'value' attribute for the dataTable is a java.util.List of a RowEntry objects. There is one RowEntry object in the list for each row in the table and it contains a java.util.List with an entry for each column cell in the row. My JSP tried to use another forEach tag where the items value was that list but it always fails. My JSP looks like:

      <rich:dataTable cellpadding="0" cellspacing="0" value="#{dynamictablebb.rowList}"
       styleClass="DataGrid" rowClasses="ListRow" var="cellvar">
       <f:facet name="header">
       <rich:columnGroup>
       <c:forEach var="avar" items="#{dynamictablebb.colHeaderList}">
       <rich:column styleClass="richFacesColClass" >
       <h:outputText value="#{avar}" styleClass="ListHeading"/>
       </rich:column>
       </c:forEach>
       </rich:columnGroup>
       </f:facet>
       <c:forEach var="t" items="#{cellvar.rowEntries}">
       <rich:column>
       <h:outputText value="{t}"/>
       </rich:column>
       </c:forEach>
      </rich:dataTable>


      When I try to run this I get the error
      javax.servlet.ServletException: Don't know how to iterate over supplied "items" in <forEach>


      Yet if I replace my forEach and just put in
      <rich:column>
       <h:outputText value="#{cellvar.rowEntries}"/>
      </rich:column>

      Then that outputs the contents of the list that getRowEntries returns.

      It's quite possible that this is a problem arising due to my lack of JSP and JSTL knowledge but if so would be great know why the forEach tag doesn't like getting back a list (when it works fine for iterating through the header names).

      Thanks,
      Aoife