3

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.

Matteo
  • 14,696
  • 9
  • 68
  • 106
Martin
  • 94
  • 2
  • 12
  • You should probably use `` to render dymanic number of columns: http://livedemo.exadel.com/richfaces-demo/richfaces/columns.jsf?tab=usage&cid=1222466 – Magnilex May 06 '13 at 09:19
  • @MagnusTengdahl `` are unfortunatelly out of Final scope. I got that here: [link](https://community.jboss.org/message/592975) – Martin May 06 '13 at 13:06

1 Answers1

3

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.

Makhiel
  • 3,874
  • 1
  • 15
  • 21
  • 1
    Hi @Makhiel Thanks for your answer. You got right, it is impossible to access the attributes from the rich:dataTable inside the c:forEach. Your approche to get it with the little hack works. For my example works this hack only because I access another attribute (reportingModel.headerList) which has the same length as the reportingDoiPoolRow.amountOfDois List. If you really need this inside the c:forEach you got any alternatives? Thanks, I really appreciate your help. – Martin May 06 '13 at 13:02
  • Won't it always have the same length? If not just save the actual length somewhere in the bean so you can access it. – Makhiel May 06 '13 at 13:14
  • OK, that is a good idea. Imagine that I have months in the header and for every month a total value and a new value. That means two columns for one month. I solved it with that code, because I can not access the reportingDoiPoolRow.amountOfDois list: ` ` – Martin May 06 '13 at 13:21
  • Thanks a lot, mate. I wasted almost a week figuring out this ridiculous behavior. Too bad they removed `` in Richfaces 4.x else this hack wouldn't have been required.. – Vrushank Dec 19 '13 at 07:06