Dataexporter returns empty rows after filtering

人盡茶涼 提交于 2019-12-08 09:19:50

问题


I have a datatable in my xhtml view with filtering enabled. Additionally, there's the Primefaces export (for Excel) function in the context menu. When I use this function without filtering the datatable it works fine, but when I filter first and den export the data I get a file with empty rows.

This is my code:

<p:panel header="#{msg['prs.list']}">
    <p:contextMenu for="persons">
        <p:menuitem value="#{msg['com.view']}" icon="#{msg['icon.view']}"
                    action="#{personBean.redirectToEditPerson}"/>
        <p:menuitem value="#{msg['student.new']}" icon="#{msg['icon.new']}"
                    action="#{personBean.redirectToNewStudent}"/>
        <p:menuitem value="#{msg['prs.new']}" icon="#{msg['icon.new']}"
                    url="edit.xhtml"/>
        <p:menuitem value="#{msg['report.export.excel']}" ajax="false" icon="#{msg['icon.export']}">
            <p:dataExporter type="xls" target="persons" fileName="export"  />
        </p:menuitem>
    </p:contextMenu>
    <p:dataTable id="persons" var="person" value="#{personBean.personList}"
                 rowKey="#{person.id}" selection="#{personBean.selectedPerson}" selectionMode="single"
                 emptyMessage="#{msg['com.noEntries']}" paginator="true" rows="15">

        <p:column headerText="Id">
            <h:outputText value="#{person.id}"/>
        </p:column>

        <p:column headerText="#{msg['prs.name']}" filterBy="name" filterMatchMode="contains">
            <h:outputText value="#{person.name}"/>
        </p:column>

        <p:column headerText="#{msg['prs.surname']}" filterBy="surname" filterMatchMode="contains">
            <h:outputText value="#{person.surname}"/>
        </p:column>

        <p:column headerText="#{msg['prs.email']}" filterBy="email" filterMatchMode="contains">
            <h:outputText value="#{person.email}"/>
        </p:column>

    </p:dataTable>
    <f:facet name="footer">
        <p:button value="#{msg['prs.new']}" icon="#{msg['icon.new']}"
                  outcome="edit"/>
    </f:facet>
</p:panel>

I'm using Primefaces 4, JSF 2 and Java 7 on Wildfly 8


回答1:


Solved. I found a warning in my log regarding the filteredValue property of the datatable.

[0m[33m17:26:45,701 WARNING [org.primefaces.component.datatable.DataTable] (default task-4) DataTable form:persons has filtering enabled but no filteredValue model reference is defined, for backward compatibility falling back to page viewstate method to keep filteredValue. It is highly suggested to use filtering with a filteredValue model reference as viewstate method is deprecated and will be removed in future.

I therefore added this property which then solved the problem

<p:dataTable id="persons" var="person" value="#{personBean.personList}" 
    rowKey="#{person.id}" selection="#{personBean.selectedPerson}" 
    selectionMode="single" emptyMessage="#{msg['com.noEntries']}" 
    paginator="true" rows="15" filteredValue="#{personBean.filtered}">

And added the following property in PersonBean as well

private List<PersonEntity> filtered;
public List<PersonEntity> getFiltered() { return filtered; }
public void setFiltered(List<PersonEntity> filtered) { this.filtered = filtered; }


来源:https://stackoverflow.com/questions/25608691/dataexporter-returns-empty-rows-after-filtering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!