Dataexporter在过滤后返回空行 [英] Dataexporter returns empty rows after filtering

查看:179
本文介绍了Dataexporter在过滤后返回空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的xhtml视图中有一个datatable,并启用了过滤器。此外,在上下文菜单中有Primefaces导出(用于Excel)功能。当我使用这个功能不过滤datatable它工作正常,但是当我先过滤,并导出数据我得到一个空行的文件。

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>

我在Wildfly 8上使用了Primefaces 4,JSF 2和Java 7。 $ b

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

推荐答案

已解决。我在日志中发现有关datatable的filteredValue属性的警告。

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}">

并在PersonBean中添加以下属性:

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; }

这篇关于Dataexporter在过滤后返回空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆