我从 PrimeFaces 6.1 迁移到 10.0.0,现在项目中的每个
sortBy
p:dataTable
都不起作用。
我的
p:dataTable
的一个例子:
<p:dataTable widgetVar="truckListTable" id="truckListTable" var="truck" value="#{truckList.trucks}"
sortBy="#{truck.code}" sortMode="single" filteredValue="#{truckList.filteredTrucks}" paginator="true"
paginatorPosition="top" rows="20" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
...
<p:column sortBy="#{truck.plate}" filterBy="#{truck.plate}" filterMatchMode="contains">
<h:outputText value="#{truck.plate}" />
</p:column>
...
</p:dataTable>
我在我的 bean 中定义了
truck
变量 truckList
:
private List<Map> trucks;
public List<Map> getTrucks() {
return trucks;
}
public void setTrucks(List<Map> trucks) {
this.trucks = trucks;
}
我的问题是当我单击列标题时,表格行未排序。
filterBy
工作正常,但sortBy
不行。我哪里做错了?
文档指出
sortBy
需要单个或一组 SortMeta
。这在从8到10迁移指南中也提到了。
因此,要么从您的 bean 中提供
SortMeta
,要么简单地将 sortOrder
添加到“代码”的 p:column
。
SortMeta
可以这样创建:
SortMeta.builder().field("code").order(SortOrder.ASCENDING).build();
另请参阅:
遇到了同样的问题,这花了我几个小时。
偶然发现了这个线程:https://github.com/primefaces/primefaces/issues/7232#issuecomment-822529549
将
javax.faces.STATE_SAVING_METHOD
更改为 server
解决了该问题。
尝试在您的
web.xml
中添加/替换
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
对我来说,问题是通过将 dataTable 包装在表单标签中解决的:
<h:form id="applicationsForm">
<p:dataTable id="applicationsTable" var="applicationValue" value="#{applicationsListBean.applications}" sortMode="single" >