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

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

问题描述

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



我有一个类 Event 与属性列表< GameRecord> gameRecordList GameRecord 包括列表<布尔> gamesEntered 等属性。这个想法是我有一个活动中的人的列表,并且配置是否被输入投注或比赛。



在我的.xhtml文件中我有

 < p:dataTable value =#{events.gameRecordList}var =itemrowIndexVar =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> ,但是无论哪种方式,这个数据应该出现在空白处。



这是否有意义,或者是否需要完整的解决方案才能使其发挥作用?

解决方案


< c:forEach> 应该与 value =#{item.gamesEntered}而不是完整的字符串,但它不是。


JSTL标签在视图构建时运行,构建JSF组件树。 JSF组件在视图呈现时运行,生成HTML输出。所以现在,< c:forEach> 运行,< p:dataTable> 尚未运行 var 无处可用,将作为 null 进行评估。请注意,这同样适用于 rowIndexVar ,它将以 0 (默认值

另请参见









我尝试过 :重复> ,但是无论哪种方式,这个数据应该出现在空白处。


UIData 组件只能接受 UIColumn 儿童。 < ui:repeat> 不是这样的。 < c:forEach> 的工作原理是因为它基本上产生一堆物理的< p:column> 数据表。你很幸运,每个项目显然是相同数量的 gamesEntered 作为第一个项目,否则将会失败。



另请参见:








顺便说一下,您需要< p:columns> 这基本上是一个< ui:repeat> UIColumn 类扩展。但是,在这里,它的不能在每行的基础上进行设置,只能在每个表的基础上。 rowIndexVar < p:columns value> 中不可用,并将评估为 0

 < p:dataTable value =#{events.gameRecordList}var =itemrowIndexVar =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>



另请参见:




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

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.

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>

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?

解决方案

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

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

See also


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

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.

See also:


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>

See also:

这篇关于为什么可以&lt; c:forEach&gt;或&lt; ui:repeat&gt;不访问&lt; p:dataTable var&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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