3

I want to generate a list of tables. 1 table for each month. With 1 column for each day of the month. Here is the JSF piece I am using.

<ui:repeat value="#{worklogService.months}" var="monthnum">
    <p:dataTable value="#{worklogService.getTableForMonth(monthnum)}" var="tabrow">
        <p:column headerText="Name">
            <h:outputLabel value="#{tabrow.get(0)}"></h:outputLabel>
        </p:column>
        <ui:repeat value="#{worklogService.getDaysOfMonth(monthnum)}" var="daynum">
            <p:column headerText="#{daynum}">
                <h:outputText value="#{tabrow.get(daynum)}"></h:outputText>
            </p:column> 
        </ui:repeat>
    </p:dataTable>
</ui:repeat>

#{worklogService.months} returns List<Integer>. One number per Month. #{worklogService.getTableForMonth(monthnum)} returns List<List<String>>.

The first column for each table is the same. I want to generate all other columns depending on the month. The result is 12 Tables with only 1 column (the first). What could be the problem here? And how to solve it?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
FuryFart
  • 2,304
  • 4
  • 27
  • 43

1 Answers1

15

This construct fails because UIData components like <p:dataTable> only support UIColumn children which can in case of <p:dataTable> only be either <p:column> or <p:columns>.

In your particular case, you've 2 options:

  1. Use <p:columns> instead of <ui:repeat><p:column>:

    <p:columns value="#{worklogService.getDaysOfMonth(monthnum)}" var="daynum" headerText="#{daynum}">
        #{tabrow.get(daynum)}
    </p:columns> 
    
  2. Use <c:forEach> instead of <ui:repeat> (explained here):

    <c:forEach items="#{worklogService.getDaysOfMonth(monthnum)}" var="daynum">
        <p:column headerText="#{daynum}">
            <h:outputText value="#{tabrow.get(daynum)}"></h:outputText>
        </p:column> 
    </c:forEach>
    
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Solution 1 won't work due to [this bug](https://code.google.com/p/primefaces/issues/detail?id=6276) in PrimeFaces >4.0(.x) that they 'refuse' to fix (or at least closed for a wrong reason). It happens in other 'repeating' components to like tab and their own datatable. – Kukeltje Mar 29 '15 at 11:05
  • @balus c when in use the datatable inside the ui:repeat scroll bar inside the datatable not working properly (if i scroll my first datatable horizontal scroll bar ,alone with my datatable the second datatable header is also getting scrolled ) – goku Jun 09 '16 at 13:27