0
votes

My data structure is like this:

ObjectA contains Strings varA, varB and a List of 24 ObjectBs.

ObjectB contains Strings varC,varD,varE.

I now have a List of ObjectAs.

I am trying to use a Primefaces datatable to get an output like this (in a table). (for each ObjectA)

How do I achieve this? In the screenshot below, the first column is the row index, the second column is the varA from ObjectA, third column is varB from ObjectA. Columns with headers 1 to 24 are the values of ONLY varC from each of the 24 ObjectBs. In the second row, columns with headers 1 to 24 are the values of ONLY varD from each of the 24 ObjectBs. In the third row, columns with headers 1 to 24 are the values of ONLY varE from each of the 24 ObjectBs. After three rows are complete, now I take the next objectA2 and repeat the process. I was able to do this in a jsp using c:forEach tags. However, I am unable to get this done using JSF.

enter image description here

I even tried during normal HTML table using ui:repeat but if there are two ObjectB ui:repeats inside the ObjectA ui:repeat, only one of the ui:repeats is working and the other one is showing blank values.

                    <ui:repeat var="upto" value="#{getClearedTransactionsBean.clearedList}" varStatus="rowCounter">
                        <tr>
                            <td rowspan="3">#{rowCounter.index+1}</td>

                            <td><h:outputText value="#{upto.sink}"/></td>
                            <td>Cleared MW</td>

                            <ui:repeat value="#{upto.hourlyClearedList}" var="hourly">
                                <td><h:outputText value="#{hourly.clearedMW}"/></td>
                            </ui:repeat>

                        </tr>
                        <tr>
                            <td><h:outputText value="#{upto.sourceLocationLabel}"/></td>
                            <td>Source LMP</td>
                            <ui:repeat items="#{upto.hourlyClearedList}" var="hourly">
                                <td><h:outputText value="#{hourly.sourceLMP}"/></td>
                            </ui:repeat>
                        </tr>   
                        <tr>
                            <td></td>
                            <td>Sink LMP</td>
                            <ui:repeat items="#{upto.hourlyClearedList}" var="hourly">
                                <td><h:outputText value="#{hourly.sinkLMP}"/></td>
                            </ui:repeat>
                        </tr>   
                        <tr class="blankrow">
                            <td colspan="27"></td>
                        </tr>
                    </ui:repeat>

                </table>

The above screenshot is the one that I did successfully in a jsp. But, I need to do this in JSF 2. Thanks !

1

1 Answers

0
votes

Try to use dynamic columns. Prepare model for rows, may be object with columns data in HashMap.

http://www.primefaces.org/showcase/ui/data/datatable/columns.xhtml