我在这里遇到了一个问题,我的系统配置是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。
在我写了一些代码之后,根据我的期望,它可以工作,但它不是:(
这段代码完美地呈现了头部,但是紧跟在ui:repeat代码之后,它不会呈现其中的p:row和p: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> 我是不是错过了什么?
还是说这只是个bug?因为我在谷歌上搜索这类代码,但什么也没找到。
致以敬意,
bLueZ
发布于 2013-03-13 00:40:08
感谢@Jedrus07建议我发布一个答案。
实际上,我所做的是使用<p:dataTable/>来很好地显示数据。示例:
<p:tabView id="tabCustomerView">
<p:tab title="Fasilitas Nasabah">
<p:fieldset legend="Detil Fasilitas">
<p:dataTable value="#{custViewBean.customerSavingAccounts}"
var="customerSavingAccount"
rowIndexVar="customerSavingAccountRowIndex"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rows="10"
rowsPerPageTemplate="5,10,15"
paginatorPosition="top">
<f:facet name="header">
<h:outputText value="Daftar Rekening / Fasilitas Nasabah"/>
</f:facet>
<p:column headerText="#">
<h:outputText value="#{customerSavingAccountRowIndex + 1}"/>
</p:column>
<p:column headerText="Fasilitas Nasabah">
<h:outputText value="#{of:capitalize(customerSavingAccount.customerFacility)}"/>
</p:column>
<p:column headerText="Saldo Akhir">
<h:outputText value="#{customerSavingAccount.lastBalance}">
<f:convertNumber type="currency" currencySymbol="#{appBean.appSetting.curDefault.currencySymbol}"/>
</h:outputText>
</p:column>
<p:column headerText="Tanggal Akhir">
<h:outputText value="#{customerSavingAccount.lastTransactiondate}">
<f:convertDateTime pattern="#{appBean.appSetting.siteFormatdate}"/>
</h:outputText>
</p:column>
<p:column headerText="Suku Bunga">
<h:outputText value="#{customerSavingAccount.interest} %"/>
</p:column>
<p:column headerText="Kolektibilitas">
<h:outputText value="#{customerSavingAccount.collectibility}"/>
</p:column>
<p:column headerText="Account Officer">
<h:outputText value="#{of:capitalize(customerSavingAccount.accountOfficer)}"/>
</p:column>
<p:column headerText="Jumlah Tunggakan">
<h:outputText value="#{customerSavingAccount.arrearsAmount}">
<f:convertNumber type="currency" currencySymbol="#{appBean.appSetting.curDefault.currencySymbol}"/>
</h:outputText>
</p:column>
<p:column headerText="Jumlah Pembayaran">
<h:outputText value="#{customerSavingAccount.totalPayment}">
<f:convertNumber type="currency" currencySymbol="#{appBean.appSetting.curDefault.currencySymbol}"/>
</h:outputText>
</p:column>
<p:column headerText="Periode Pembayaran">
<h:outputText value="#{customerSavingAccount.termLimit} #{customerSavingAccount.termLimitDesc}"/>
</p:column>
<p:column headerText="Status">
<h:outputText value="#{customerSavingAccount.status}"/>
</p:column>
</p:dataTable>
</p:fieldset>
</p:tab>
</p:tabView>因此,使用datatable来获得更好的外观来显示您的数据:)玩得开心。
发布于 2013-03-14 04:28:17
至于具体问题,<ui:repeat>是一个视图渲染时间标签。因此,它以物理方式出现在JSF组件树中,并生成其HTML输出,次数与遍历该值所需的次数相同。
然而,<p:panelGrid>期望物理上有多个<p:row>或<p:column>子代,而不是其中具有单个<ui:repeat>的单个<p:row>。换句话说,它们需要在视图构建时准备好,而不是在视图呈现时准备。
JSTL <c:forEach>是视图构建时间标记。它将在JSF组件树中物理地生成多个<p:row>组件,因此<p:panelGrid>将只找到<p:row>子组件。
<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版本中的视图作用域bean。如果你不能升级,那么考虑一下<p:dataTable>,因为你自己已经发现了。
另请参阅:
https://stackoverflow.com/questions/10719233
复制相似问题