I'm building a rich datatable with a dynamic amount of columns. It seems to me, that it is not a big thing, but I'm trying to get an answer since hours. The issue is when I want to use the iteration variable from the datatable for a nested loop. In the nested loop I try to create for every row the same dynamic amount of columns. Probably it becomes more clear when I show some code:
<rich:dataTable styleClass="waiDataTable" width="700"
rowClasses="odd,even" value="#{reportingModel.reportingDoiPoolRows}"
var="reportingDoiPoolRow"
rendered="#{not empty reportingModel.reportingDoiPoolRows}">
<!-- Start header of the data-table -->
<f:facet name="header">
<rich:columnGroup>
<rich:column rowspan="2">
<h:outputText value="Pool" />
</rich:column>
<c:forEach items="#{reportingModel.headerList}" var="item">
<rich:column colspan="2">
<h:outputText value="#{item}" />
</rich:column>
</c:forEach>
<rich:column breakRowBefore="true">
<h:outputText value="New" />
</rich:column>
<rich:column>
<h:outputText value="Tot" />
</rich:column>
<c:forEach begin="1" end="#{reportingModel.headerList.size()-1}">
<rich:column>
<h:outputText value="New" />
</rich:column>
<rich:column>
<h:outputText value="Tot" />
</rich:column>
</c:forEach>
</rich:columnGroup>
</f:facet>
<!-- End header of the data-table -->
<!-- Start values of the data-table -->
<rich:column>
<h:outputText value="#{reportingDoiPoolRow.doiPool.name}"></h:outputText>
</rich:column>
<ui:repeat value="#{reportingDoiPoolRow.amountOfDois}" var="amount">
<rich:column style="text-align:right;">
<h:outputText value="#{amount}"/>
</rich:column>
</ui:repeat>
<!-- Start values of the data-table -->
<f:facet name="footer">
<rich:columnGroup>
<rich:column style="text-align:left;">Totals</rich:column>
<rich:column style="text-align:right;">
<h:outputText value="12"></h:outputText>
</rich:column>
<rich:column style="text-align:right;">
<h:outputText value="12"></h:outputText>
</rich:column>
</rich:columnGroup>
</f:facet>
The issue is in the following block:
<rich:column>
<h:outputText value="#{reportingDoiPoolRow.doiPool.name}"></h:outputText>
</rich:column>
<ui:repeat value="#{reportingDoiPoolRow.amountOfDois}" var="amount">
<rich:column style="text-align:right;">
<h:outputText value="#{amount}"/>
</rich:column>
</ui:repeat>
The name (reportingDoiPoolRow.doiPool.name
) is rendered well but every column inside the ui:repeat
is not rendered.
It seems that I can't use the reportingDoiPoolRow variable for another iteration.
The Collections which I use for the table are both from the type ArrayList
(long).
Thank you very much for your help.
I think <ui:repeat>
doesn't work because <rich:column>
is not what ui:repeat is designed to deal with (e.g. a <li>
or something like that), <a4j:repeat>
which you should be using instead won't work there either (and that has something to do with the way the table is built).
<c:forEach>
will work, with a little hack:
<c:forEach var="index" begin="0" end="#{reportingModel.columns - 1}">
<rich:column style="text-align:right;">
<h:outputText value="#{reportingDoiPoolRow.amountOfDois.get(index)}" />
</rich:column>
</c:forEach>
<c:forEach>
does not have access to the attributes from <rich:dataTable>
(well, it has access to rowKeyVar
but that will be always 1) so you'll have to ask the bean directly for the column size but the pieces rendered by <c:forEach>
will have access to the var
.