[英]PrimeFaces DataTable Sorting & Filtering don't work with JSF DataModel
我有3個測試Web應用程序,使用相同的模型和控制器,不同之處在於JSF會話托管bean。
應用程序A和C使用JSF DataModel檢索項目:JPA查詢結果集返回一個Java LIST,然后將其包裝在ListDataModel中。 后者的值是PrimeFaces dataTable顯示的項目。
應用程序B使用Java LIST檢索項目:JPA查詢結果集返回一個Java List,它是PrimeFaces 2.2.1 dataTable顯示的項目值。
應用程序B中的排序和篩選功能齊全且快速,而在應用程序A和C中則不是致命的。
我只想提到在排序其他庫(如Richfaces,OpenFaces)中進行過濾時,可以使用相同的代碼直接使用。
該問題也仍然存在於PrimeFaces 3.0.0中。 這是錯誤嗎?
碼:
private List<Customer> items = null;
// remainder of code here
public List<Customer> getCustomerItems() {
if (customerItems == null) {
getPagingInfo();
customerItems = jpaController.findCustomerEntities(pagingInfo.getBatchSize(), pagingInfo.getFirstItem());
}
return customerItems;
}
在應用A中:
碼:
private DataModel items = null;
public PaginationHelper getPagination() {
if (pagination == null) {
pagination = new PaginationHelper(999999) {
@Override
public int getItemsCount() {
return getJpaController().getChimioCount();
}
@Override // The list of Customers is wrapped in a JSF ListDataModel
public DataModel createPageDataModel() {
return new ListDataModel(getJpaController().findCustomerEntities(getPageSize(), getPageFirstItem()));
}
};
}
return pagination;
}
/**
* this goes for the value attribute in a datatable to list all the Customer items
*/
public DataModel getItems() {
if (items == null) {
items = getPagination().createPageDataModel();
}
return items;
}
在應用C中:
碼:
private DataModel<Project> items;
// remainder of code here
/**
*The ListDataModel is initialized here
*/
public void init() {
try {
setProjectList(doInTransaction(new PersistenceAction<List<Project>>() {
public List<Project> execute(EntityManager em) {
Query query = em.createNamedQuery("project.getAll");
return (List<Project>) query.getResultList();
}
}));
} catch (ManagerException ex) {
Logger.getLogger(ProjectManager.class.getName()).log(Level.SEVERE, null, ex);
}
projectItems = new LinkedList<SelectItem>();
projectItems.add(new SelectItem(new Project(), "-- Select one project --"));
if (getProjectList() != null) {
projects = new ListDataModel<Project>(getProjectList());
for (Project p : getProjectList()) {
projectItems.add(new SelectItem(p, p.getName()));
}
}
}
預先感謝您的幫助。
這可能是PrimeFaces錯誤。 我已經看到了有關使用數據模型時DataTable排序問題的一些討論。 這是指向其跟蹤器中PrimeFaces缺陷之一的鏈接 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.