2012-07-10 52 views
1

在我的應用程序中,我使用全局過濾器搜索Primefaces DataTable中的記錄,並且我在同一DataTable上應用了DataExporter。DataExporter不適用於Primefaces 3.2中的已過濾數據表0123:

當我搜索任何記錄並導出時,它會返回一個完整的數據列表,而不是過濾列表。

我的開發環境是: 的Java 6.0,Primefaces 3.2,JSF2.1,GlassFish應用服務器3.1.2,7.1.1 Netbeans的


入伍低於我的DataTable,並dataExporter代碼。

我dataTable的代碼::

<p:dataTable value="#{personnelController.allItems}" 
            emptyMessage="#{bundle.PersonnelEmpty}" 
            selectionMode="single" 
            dblClickSelect="false" 
            var="item" 
            id="tbl" 
            rowKey="#`enter code here`{item.id}" 
            sortBy="#{item.lastName}" 
            sortOrder="ascending" 
            widgetVar="itemTable" 
            paginator="true" 
            paginatorPosition="bottom" 
            paginatorAlwaysVisible="false" 
            currentPageReportTemplate="Page {currentPage} of {totalPages}" 
            paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" 
            rows="10" 
            > 
          <f:facet name="header"> 
           <p:outputPanel> 
            <h:outputText value="#{bundle.GlobalFilterPrompt}" /> 
            <p:inputText id="globalFilter" 
               onkeyup="itemTable.filter()" 
               style="width:150px;" 
               /> 
            <p:watermark for="globalFilter" value="#{bundle.GlobalFilterWatermark}" /> 
           </p:outputPanel> 
          </f:facet> 
          <p:ajax event="rowSelect" listener="#{personnelController.onRowSelectNavigate}" /> 

          <p:column 
           sortBy="#{item.lastName}" 
           filterBy="#{item.lastName}" 
           filterStyle="display: none;" 
           > 
           <f:facet name="header"> 
            <h:outputText value="#{bundle.PersonnelTitle_lastName}"/> 
           </f:facet> 
           <h:outputText value="#{item.lastName}"/> 
          </p:column> 
          <p:column 
           sortBy="#{item.firstName}" 
           filterBy="#{item.firstName}" 
           filterStyle="display: none;" 
           > 
           <f:facet name="header"> 
            <h:outputText value="#{bundle.PersonnelTitle_firstName}"/> 
           </f:facet> 
           <h:outputText value="#{item.firstName}"/> 
          </p:column> 
          <p:column 
           sortBy="#{item.location.name}" 
           filterBy="#{item.location.name}" 
           filterStyle="display: none;" 
           > 
           <f:facet name="header"> 
            <h:outputText value="#{bundle.PersonnelTitle_locations}"/> 
           </f:facet> 
           <h:outputText value="#{item.location.name}"/> 
          </p:column> 
          <p:column 
           sortBy="#{item.department.name}" 
           filterBy="#{item.department.name}" 
           filterStyle="display: none;" 
           > 
           <f:facet name="header"> 
            <h:outputText value="#{bundle.PersonnelTitle_departments}"/> 
           </f:facet> 
           <h:outputText value="#{item.department.name}"/> 
          </p:column> 

         </p:dataTable> 

我從數據表外導出表數據爲::

<h:commandLink> 
     <p:graphicImage value="#{resource['images:excel.png']}" /> 
     <p:dataExporter type="xls" target=":personnel:tbl" fileName="personnel" /> 
</h:commandLink> 

請建議我,如果我做錯什麼。

+0

我使用dataexporter用過濾的數據表,並出口僅過濾後的數據。你能發佈你的代碼嗎? – fareed 2012-07-11 05:43:03

+0

看到我更新的答案,我希望這可以解決您的問題 – fareed 2012-07-14 04:38:29

回答

2

這是我的一個用戶表的例子:

<p:dataTable id="table" value="#{myBean.users}" var="usr" rowKey="#{usr.username}" widgetVar="usrwv"> 
     <f:facet name="header"> 
      <p:outputPanel> 
       <h:outputText value="Search all fields:" /> 
       <p:inputText id="globalFilter" onkeyup="usrwv.filter()" style="width:150px" /> 
      </p:outputPanel> 
     </f:facet> 
     <p:column headerText="Username" sortBy="#{usr.username}" filterBy="#{usr.username}"> 
       <f:facet name="header"> 
        Username 
       </f:facet> 
       <h:outputText value="#{usr.username}"/> 
     </p:column> 
     <p:column headerText="Role" sortBy="#{usr.role}" filterBy="#{usr.role}"> 
       <f:facet name="header"> 
        Role 
       </f:facet> 
       <h:outputText value="#{usr.role}"/> 
     </p:column> 
     <f:facet name="footer"> 
       <h:commandLink> 
        <p:graphicImage value="/resources/images/excel.ico" title="myExcel"/> 
        <p:dataExporter type="csv" target="table" fileName="all_users"/> 
       </h:commandLink> 
     </f:facet> 
</p:dataTable> 

而且你是把出口和在兩種不同形式的數據表。試着把它們放在同一個表格中。這應該工作。

+0

謝謝Fareed! 通過把DataTable和DataExporter放在一個表單中我已經得到了期望的結果:) – anushri 2012-07-20 06:49:22

+0

@anushri我很高興它爲你工作:) – fareed 2012-07-21 06:21:03

+0

@anushri http://meta.stackexchange.com/questions/5234/how -does接受-的回答工作 – 2013-05-16 05:34:41

0

在pom.xml:

<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>3.10.1</version> 
</dependency> 

<dependency> 
    <groupId>com.itextpdf</groupId> 
    <artifactId>itextpdf</artifactId> 
    <version>5.5.3</version> 
</dependency> 

而更換:

<h:commandLink> 
     <p:graphicImage value="#{resource['images:excel.png']}" /> 
     <p:dataExporter type="xls" target=":personnel:tbl" fileName="personnel" /> 
</h:commandLink> 

<h:commandLink> 
     <h:graphicImage value="#{resource['images:excel.png']}" /> 
     <p:dataExporter type="xls" target=":personnel:tbl" fileName="personnel" /> 
</h:commandLink> 
相關問題