gpt4 book ai didi

jsf - 为什么可以 or not access ?

转载 作者:行者123 更新时间:2023-12-04 19:37:00 24 4
gpt4 key购买 nike

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

我有一个类Event有房产List<GameRecord> gameRecordList . GameRecord包括 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 标记在 View 构建期间运行,构建 JSF 组件树。 JSF 组件在 View 呈现期间运行,生成 HTML 输出。所以目前 <c:forEach>运行, <p:dataTable>还没有运行和它的 var无处可用,将评估为 null .请注意,这同样适用于 rowIndexVar ,这将评估为 0 ( int 的默认值)。

也可以看看
  • 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 组件只能接受 UIColumn children 。 <ui:repeat>不是这样的。 <c:forEach>之所以有效,是因为它基本上会产生一堆物理 <p:column>数据表的组件。你很幸运,每件元素都有明显相同数量的 gamesEntered作为第一项,否则这也会失败。

    也可以看看:
  • How to use ui:repeat in datatable to append columns?


  • 顺便说一句,你需要 <p:columns>这基本上是一个 <ui:repeat>UIColumn 延伸类(class)。但也在这里,它的 value不能在每行的基础上设置,只能在每个表的基础上设置。 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>
  • 关于jsf - 为什么可以 <c :forEach> or <ui:repeat> not access <p:dataTable var>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29021036/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com