DataTable作为复合组件,LazyDataModel不起作用

时间:2013-10-30 12:28:37

标签: jsf jsf-2 primefaces datatable composite-component

我在尝试使用primefaces数据表作为复合组件时遇到问题。 以下是我的代码段: commonDataTable.xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:f="http://java.sun.com/jsf/core"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:composite="http://java.sun.com/jsf/composite"
   xmlns:p="http://primefaces.org/ui">

<composite:interface>
   <composite:attribute name="rows" />
   <composite:attribute name="value" type="org.primefaces.model.LazyDataModel"/>
   <composite:attribute name="var" />
   <composite:attribute name="id" />
   <composite:attribute name="rowStyle" />
</composite:interface>

<composite:implementation>
      <p:dataTable value="#{composite.attrs.value}"
                  rendered="#{not empty composite.attrs.value}"
                  id="composite.attrs.id" var="composite.attrs.var" paginator="true" rows="25"
                  currentPageReportTemplate="Showing {startRecord}-{endRecord} of {totalRecords}"
                  paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                  rowsPerPageTemplate="25,50,100" paginatorPosition="bottom"
                  lazy="true" rowStyleClass="#{composite.attrs.rowStyle}">
                  <composite:set target="#{component}" property="var" value="#{composite.attrs.var}"/>
      <composite:insertChildren />
      </p:dataTable>
</composite:implementation>

</ui:composition>

的index.xhtml:

<ui:composition template="/WEB-INF/template/layout.xhtml"
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:f="http://java.sun.com/jsf/core"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:p="http://primefaces.org/ui"
   xmlns:t="http://java.sun.com/jsf/composite/components">

   <ui:param name="pageTitle" value="My Page" />

   <f:metadata>
      <f:viewParam id="employeeId" name="employeeId" value="#{mySummaryBean.employeeId}" required="false" />
      <f:viewParam id="employee" name="employee" value="#{mySummaryBean.employee}" required="false" />
      <f:event type="preRenderView" listener="#{mySummaryBean.preRender}" />
   </f:metadata>

   <ui:define name="content">
      <p:fieldset>
         <h2>employee Overview</h2>

         <h:form>
            <p:messages id="messages" showDetail="true" autoUpdate="true"
               closable="true" />
            <p:panel rendered="#{not empty mySummaryBean.employeeRunModel}">
               <t:commonDataTable var="run" value="#{mySummaryBean.employeeRunModel}" rows="10"
                                 id="carTable"
                                 rowStyle="#{run.runErrorStatus}">

                         .........
               </t:commonDataTable>
            </p:panel>
         </h:form>
      </p:fieldset>
   </ui:define>
</ui:composition>

是否有人使用LazyDataModel在复合组件内部使用数据表?

1 个答案:

答案 0 :(得分:3)

使用Primeface后,我现在能够解决问题。共享解决方案,以便在需要时可以帮助其他人。 commonDataTable.xhtml:

<ui:component xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:cc="http://java.sun.com/jsf/composite"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:p="http://primefaces.org/ui">

    <cc:interface>
        <cc:attribute name="rows" />
        <cc:attribute name="value"
            type="org.primefaces.model.LazyDataModel" />
        <cc:attribute name="var" />
        <cc:attribute name="id" />
        <cc:attribute name="rowStyle" />
    </cc:interface>

    <cc:implementation>
        <p:dataTable value="#{cc.attrs.value}"
            rendered="#{not empty cc.attrs.value}" id="#{cc.attrs.id}"
            paginator="true" rows="25" 
            currentPageReportTemplate="Showing {startRecord}-{endRecord} of     {totalRecords}"
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="25,50,100" paginatorPosition="bottom"
            lazy="true" rowStyleClass="#{cc.attrs.rowStyle}">
             <c:set target="#{component}" property="var" value="#{cc.attrs.var}"/>
            <cc:insertChildren />
        </p:dataTable>
    </cc:implementation>
    </ui:component>

的index.xhtml:

<ui:composition template="/WEB-INF/template/layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:t="http://java.sun.com/jsf/composite/components">

<ui:param name="pageTitle" value="My Page" />

<ui:define name="content">
  <p:fieldset>
     <h2>employee Overview</h2>

     <h:form>
        <p:messages id="messages" showDetail="true" autoUpdate="true"
           closable="true" />
        <p:panel rendered="#{not empty mySummaryBean.employeeRunModel}">
           <t:commonDataTable var="employee" value="#{mySummaryBean.employeeRunModel}" rows="10"
                             id="employeeTable"
                             rowStyle="#{employee.employeeErrorStatus}">

                     .........
           </t:commonDataTable>
        </p:panel>
     </h:form>
  </p:fieldset>
</ui:define>
</ui:composition>