为什么<c:forEach>或<ui:repeat>不能访问<p:dataTable var>?

Why can <c:forEach> or <ui:repeat> not access <p:dataTable var>?

我正在使用 jsf Mojarra 2.2.7、Java 8、Primefaces 5.1 和 netbeans 8.0.2

我有一个 class Event 和一个 属性 List<GameRecord> gameRecordListGameRecord 包括 List<Boolean> gamesEntered 和其他属性。我的想法是我有一份活动中的人员名单,如果他们参加了投注或比赛,我正在配置。

在我的 .xhtml 文件中有

<p:dataTable value="#{events.gameRecordList}" var="item" rowIndexVar="rowIndex">

                <p:column>#{item.field1}</p:column>
                <p:column>#{item.field2}</p:column>

                <c:forEach items="#{events.gameRecordList.get(rowIndex).gamesEntered}" var="game">
                    <p:column>
                        <p:selectBooleanCheckbox value="#{game}"/>
                    </p:column>
                </c:forEach>


            </p:dataTable>

<c:forEach> 应该与 value="#{item.gamesEntered}" 一起工作,而不是完整的字符串,但事实并非如此。我已尝试 <ui:repeat>,但无论哪种方式,页面在本应出现此数据的地方都会出现空白。

这是否有意义,或者是否有理由要求完整寻址才能使其工作?

The <c:forEach> should work with value="#{item.gamesEntered}" rather than the full string but it does not.

JSTL 标记 运行 在视图构建期间构建 JSF 组件树。 JSF 组件 运行 在视图渲染期间,产生 HTML 输出。所以目前 <c:forEach> 运行s,<p:dataTable> 还没有 运行 并且它的 var 无处可用,将评估为 null。请注意,这同样适用于 rowIndexVar,它将计算为 0int 的默认值)。

另见

  • JSTL in JSF2 Facelets... makes sense?

I have tried <ui:repeat> but either way the page comes up blank where this data should have appeared.

UIData components can only accept UIColumnchildren。 <ui:repeat> 不是这样的。 <c:forEach> 之所以有效,是因为它基本上为数据表生成了一堆物理 <p:column> 组件。您很幸运,每个项目的 gamesEntered 数量显然与第一个项目相同,否则这也会失败。

另请参阅:

  • How to use ui:repeat in datatable to append columns?

顺便说一下,您需要 <p:columns>,它基本上是一个从 UIColumn class 延伸而来的 <ui:repeat>。但同样在这里,它的value不能在per-row的基础上设置,只能在per-table的基础上设置。 rowIndexVar<p:columns value> 中不可用,无论如何都会评估为 0

<p:dataTable value="#{events.gameRecordList}" var="item" rowIndexVar="rowIndex">
    <p:column>#{item.field1}</p:column>
    <p:column>#{item.field2}</p:column>
    <p:columns value="#{events.gameRecordList[0].gamesEntered}" columnIndexVar="columnIndex">
        <p:selectBooleanCheckbox value="#{events.gameRecordList[rowIndex].gamesEntered[columnIndex]}"/>
    </p:columns>
</p:dataTable>

另请参阅:

  • Primefaces static and dynamic columns in datatable
  • Dynamic columns with List<List> in <p:dataTable><p:columns>