2013-10-30 65 views
1

我在嘗試將primefaces數據表用作複合組件時遇到問題。 下面是我的代碼片段: commonDataTable.xhtml:DataTable作爲複合組件,LazyDataModel不能正常工作

<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複合組件內部的工作?

回答

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>