为什么可以 <c:forEach>或 <ui:repeat>不能访问<p:dataTable var>? [英] Why can <c:forEach> or <ui:repeat> not access <p:dataTable var>?

查看:25
本文介绍了为什么可以 <c:forEach>或 <ui:repeat>不能访问<p:dataTable var>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working with jsf Mojarra 2.2.7, Java 8, Primefaces 5.1 and netbeans 8.0.2

我有一个 Event 类,它有一个属性 List游戏记录列表.GameRecord 包括 ListgamesEntered 和其他属性.我的想法是我有一个参加活动的人员名单,并且正在配置他们是否参加投注或比赛.

I have a class Event with a property List<GameRecord> gameRecordList. GameRecord includes List<Boolean> gamesEntered and other properties. The idea is I have a list of people in an event and am configuring if they are entered into bets or competitions.

在我的 .xhtml 文件中

In my .xhtml file I have

<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>

应该使用 value="#{item.gamesEntered}" 而不是完整的字符串,但它没有.我已经尝试过 <ui:repeat> 但无论哪种方式,页面都会在该数据应该出现的地方出现空白.

The <c:forEach> should work with value="#{item.gamesEntered}" rather than the full string but it does not. I have tried <ui:repeat> but either way the page comes up blank where this data should have appeared.

这是否有意义或是否需要完整寻址才能使其工作?

Does this make sense or is there a reason the full addressing is required to make it work?

推荐答案

应该使用 value="#{item.gamesEntered}" 而不是完整的字符串,但事实并非如此.

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

JSTL 标记在视图构建期间运行,构建 JSF 组件树.JSF 组件在视图呈现期间运行,生成 HTML 输出.所以目前 运行, 还没有运行,它的 var 不可用并且将评估为 null.请注意,这同样适用于 rowIndexVar,它将计算为 0(int 的默认值).

JSTL tags run during view build time, building JSF component tree. JSF components run during view render time, producing HTML output. So at the moment <c:forEach> runs, <p:dataTable> hasn't run and its var is nowhere available and will evaluate as null. Note that the same applies to rowIndexVar, which will evaluate as 0 (the default value of an int).

我已经尝试过 但无论哪种方式,页面都会在该数据出现的地方出现空白.

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

UIData 组件只能接受 UIColumn 孩子. 不是这样的. 之所以起作用,是因为它基本上为数据表生成了一堆物理 组件.您很幸运,每个项目的 gamesEntered 数量显然与第一个项目相同,否则这也会失败.

UIData components can only accept UIColumn children. The <ui:repeat> isn't such one. The <c:forEach> works because it basically produces a bunch of physical <p:column> components for the datatable. You're lucky that each item has apparently the same amount of gamesEntered as the first item, this would otherwise have failed hard as well.

顺便说一下,你需要 它基本上是一个 UIColumn 扩展班级.但同样在这里,它的 value 不能在每行的基础上设置,只能在每个表的基础上设置.rowIndexVar 中不可用,无论如何都会评估为 0.

By the way, you need <p:columns> which is basically an <ui:repeat> which extends from UIColumn class. But also here, its value cannot be set on a per-row basis, only on a per-table basis. The rowIndexVar isn't available in <p:columns value> and would evaluate as 0 anyway.

<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>

另见:

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆