Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

jsf - How to use ui:repeat in datatable to append columns?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...