我的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
答案 0 :(得分:1)
解决。我在日志中发现了一条关于数据表的filteredValue属性的警告。
[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; }