2
votes

I have to generate a dynamic table using JSF. I have a arraylist containing headers and another list containing list of strings for holding the actual data - each entry in the main list representing a row. Is it possible to generate a dynamic table using rich:datatable? Is rich:columns an option to be considered?

2
How can I close this - so that no one else waste their time on this. - Punter Vicky
Post an answer and mark it accepted. - BalusC

2 Answers

7
votes

This code works -

<rich:dataTable 
        value="#{dataBean.getAttributeDetail().getAttributeRows()}" 
        var="dataValues" width="100%" border="1">
   <rich:columns 
            value="#{dataBean.getAttributeDetail().getAttributeHeaders()}" 
            var="columns" index="ind" id="column#{ind}">
       <f:facet name="header">
           <h:outputText value="#{columns}" />
       </f:facet>
       <h:outputText value="#{warningValues[ind]} " />
    </rich:columns>
</rich:dataTable>
3
votes

If you are using RichFaces 4, it still does not support "rich:columns", so instead use "c:forEach", like this:

<rich:dataTable value="#{teamHandler.mitarbeiter}" var="m">
   <rich:column>
      <f:facet name="header">Mitarbeiter</f:facet>
      <h:outputText value="#{m.name}" />
   </rich:column>
   <c:forEach items="#{datumsHandler.span}" var="d">
      <rich:column>
         <f:facet name="header">
            <h:outputText value="d" />
         </f:facet>
         <h:outputText value="-" />
      </rich:column>
   </c:forEach>
</rich:dataTable>

More information here.