ui:重复JSF 2.0无法呈现迭代p:行primefaces

时间:2012-05-23 11:44:39

标签: jsf-2 primefaces

我在这里遇到了问题,我的系统配置是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>  

我觉得这会产生相当丑陋的界面,所以我从主要表面跑过p:panelGrid 在我写了一些代码并且从我的期望中它会起作用,但它不会:(
此代码完美呈现标题,但在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>  
我错过了什么......? 或者这是一个错误..?因为我跑过谷歌寻找这种代码而我什么都没发现 问候,
的bluez

2 个答案:

答案 0 :(得分:6)

至于具体问题,<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>,而不是您已经发现的。

另见:

答案 1 :(得分:0)

感谢@ 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>

所以,使用数据表来获得更好的外观来显示你的数据:) 玩得开心。