我正在使用Primefaces Datatable来显示数据,我已经使用过可拖动的行并试图保存/持久化支持bean中行的重新排序
与
我可以从事件中获取索引。但是,我无法坚持对行进行重新排序:
<p:dataTable value="#{EmployeeHandler.model.employees}" var="employee" draggableRows="true">
<p:ajax event="rowReorder" listener="#{EmployeeHandler.onRowReorder}"/>
<p:column>
<h:outputText value="#{employee.id}"/
</p:column>
<p:column>
<h:outputText value="#{employee.firstName}"/
</p:column>
<p:column>
<h:outputText value="#{employee.lastName}"/
</p:column>
</p:dataTable>
我尝试了
public void onRowReorder(ReorderEvent event) {
List<Employee> employees = model.getEmployees (new order in the employees list);
fromIndex = event.getFromIndex();
toIndex = event.getToIndex();
// swapping indexes
Collections.swap(employees, fromIndex, toIndex);
}