gpt4 book ai didi

jsf-2 - ui :repeat JSF 2. 0 无法呈现迭代 p:row primefaces

转载 作者:行者123 更新时间:2023-12-01 11:01:02 26 4
gpt4 key购买 nike

我在这里遇到了问题,我的系统配置是 Mojarra 2.1.7、Primefaces 3.2 并使用 Glassfish 3.1+。

在此之前,我使用以下代码很好地呈现了我的代码:

<p:tabView>
<p:tab title="Offices Access" >
<h:outputText value="Access | Offices Name | Offices Code | Parent Offices" style="font-weight: bold;"/>

<ui:repeat value="#{userBean.officeses}" var="office">
<h:panelGrid columns="2">
<p:selectBooleanCheckbox id="access#{office.officesID}" style="width: 50px;"/>
<h:outputLabel for="access#{office.officesID}" value="#{office.officesName} | #{office.officesCode} | #{office.parentOffices}"/>
</h:panelGrid>
</ui:repeat>
</p:tab>
</p:tabView>

我发现这会生成相当难看的界面,所以我从 primefaces 中运行了 p:panelGrid
在我写了一些代码之后,按照我的预期它会工作,但它不会:(
此代码完美呈现 header ,但在 ui:repeat 代码之后,它不会呈现 p:rowp:column 内部它。

代码如下:

<p:tabView>
<p:tab title="Offices Access" >
<p:panelGrid styleClass="centerContent">
<f:facet name="header">
<p:row>
<p:column style="font-weight: bold;">Access</p:column>
<p:column style="font-weight: bold;">Offices Name</p:column>
<p:column style="font-weight: bold;">Offices Code</p:column>
<p:column style="font-weight: bold;">Above Level Offices</p:column>
</p:row>
</f:facet>

<ui:repeat value="#{userBean.officeses}" var="office">
<p:row id="rowforOffice#{office.officesID}">
<p:column><p:selectBooleanCheckbox id="access#{office.officesID}"/></p:column>
<p:column><h:outputText value="#{office.officesName}"/></p:column>
<p:column><h:outputText value="#{office.officesCode}"/></p:column>
<p:column><h:outputText value="#{office.parentOffices}"/></p:column>
</p:row>
</ui:repeat>
</p:panelGrid>
</p:tab>
</p:tabView>

我是不是错过了什么……?
或者这是一个错误..?因为我跑遍了谷歌寻找这种代码,但我一无所获。
此致,
蓝蓝Z

最佳答案

至于具体问题,<ui:repeat>是一个 View 渲染时间标签。因此,它实际存在于 JSF 组件树中,并根据需要迭代该值多次生成其 HTML 输出。

然而,<p:panelGrid>期望物理多个<p:row><p:column> child ,不是一个<ui:repeat>其中有一个 <p:row> .换句话说,它们需要在 View 构建时而不是 View 渲染时准备好。

JSTL <c:forEach>是一个 View 构建时间标签。它将在物理上生成多个 <p:row>组件进入 JSF 组件树,因此 <p:panelGrid>只会找到 <p:row> children 。

<p:panelGrid styleClass="centerContent">
<c:forEach items="#{userBean.officeses}" var="office">
<p:row id="rowforOffice#{office.officesID}">
<p:column><p:selectBooleanCheckbox id="access#{office.officesID}"/></p:column>
<p:column><h:outputText value="#{office.officesName}"/></p:column>
<p:column><h:outputText value="#{office.officesCode}"/></p:column>
<p:column><h:outputText value="#{office.parentOffices}"/></p:column>
</p:row>
</c:forEach>
</p:panelGrid>

注意:这会破坏早于 2.1.18 的 Mojarra 版本中的 View 范围 bean。如果你不能升级,那么考虑一个<p:dataTable>相反,正如您自己已经发现的那样。

另见:

关于jsf-2 - ui :repeat JSF 2. 0 无法呈现迭代 p:row primefaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10719233/

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