如何在数据表中使用ui:repeat追加列? [英] How to use ui:repeat in datatable to append columns?
问题描述
我想生成一个表列表.每月1张桌子.每个月的每一天都有1列.这是我正在使用的JSF.
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}
返回List<Integer>
.每月一个号码.
#{worklogService.getTableForMonth(monthnum)}
返回List<List<String>>
.
#{worklogService.months}
returns List<Integer>
. One number per Month.
#{worklogService.getTableForMonth(monthnum)}
returns List<List<String>>
.
每个表的第一列都是相同的.我想根据月份生成所有其他列.结果是只有1列的12个表(第一列).这可能是什么问题?以及如何解决?
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?
推荐答案
此构造失败的原因是,像<p:dataTable>
这样的UIData
组件仅支持UIColumn
子级,在<p:dataTable>
情况下只能是<p:column>
或<p:columns>
.
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>
.
在您的特定情况下,您有2个选择:
In your particular case, you've 2 options:
-
使用
<p:columns>
代替<ui:repeat><p:column>
:
<p:columns value="#{worklogService.getDaysOfMonth(monthnum)}" var="daynum" headerText="#{daynum}">
#{tabrow.get(daynum)}
</p:columns>
使用<c:forEach>
代替<ui:repeat>
(在此处说明):
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>
这篇关于如何在数据表中使用ui:repeat追加列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!