0 Replies Latest reply on Nov 25, 2009 3:47 AM by Luca Graf

    Best way for creating an dynamic crosstable

    Luca Graf Newbie


      i try to implement an 'dynamic crosstable'. The user have the ability to add both items for rows and items for columns.

      My first approach was to use the <rich:columns> tag, but like in the documentation pointed out the values must be available at component tree build time. So i think it's not possible to add row/column objects via an action/actionListener because the values will then not available when the tree is build?

      Second approach is to use <c:forEach> that works:

      <c:forEach items="#{bean.rowMapKeys}" var="objectKey" varStatus="rowIndex">
       <c:if test="#{rowIndex.index == 0}>
       <c:forEach items="#{bean.result[objectKey]}" var="property" varStatus="rowIndex">
       <th><h:outputText id="columnHead_#{rowIndex.index}_#{columnIndex}" value="#{property.label}"/></th>
       <h:outputText value="#{objectKey.name}"/>
       <rich:columns id="compareColumns_#{rowIndex.index}_#{columnIndex}" value="#{bean.result[objectKey]}" var="property" index="columnIndex">
       <h:outputText id="propertyValue_#{rowIndex.index}_#{columnIndex}" value="#{property.value}"/>

      But then i have to write my custom html for headers etc. and can't use skinning 'out of the box'.

      Two additional questions to this approach:
      1. I use <rich:column/s> tags without wrapping it in an <rich:dataTable> element (like shown in the docs) ... This is legal? The rendered html shows an table element around the tabledata elements ...

      2. I think this solution works because <c:forEach> will be evaluated at build time? But how can it works? The values for the columns will be fetched in the INVOKE_APPLICATION Phase from the db (not available at build time)... I really don't understand that?

      Third approach is to programmatic build the table and use the binding attribute like described here http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable.

      What will be the best/natural way to achieve this requirement with richfaces? Maybe some people implemented something similar and have some suggestions?

      Greetings Luca