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