0

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

这是我的代码:

<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

4

1 回答 1

2

解决了。我在日志中发现有关数据表的过滤值属性的警告。

[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.

因此,我添加了此属性,然后解决了问题

<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 中添加了以下属性

private List<PersonEntity> filtered;
public List<PersonEntity> getFiltered() { return filtered; }
public void setFiltered(List<PersonEntity> filtered) { this.filtered = filtered; }
于 2014-09-02T12:37:46.030 回答