我有3个测试web应用程序,使用相同的模型和控制器,不同之处在于JSF会话管理的bean。
-
应用程序A和C使用JSF DataModel来检索项目:JPAQuery结果集返回一个javaLIST,然后将其封装在ListDataModel中。后者的值是PrimeFaces数据表显示的项。
-
应用程序B使用JavaLIST检索项目:JPAQuery结果集返回一个javaList,它是PrimeFaces2.2.1dataTable显示的项的值。
应用程序B中的排序和过滤功能全面且快速,而在应用程序A和C中,它们并不是致命的。
我只想提一下,在其他库(如Richfaces、OpenFaces)的排序中过滤,使用相同的代码可以开箱即用。
PrimeFaces 3.0.0中也存在此问题。这是个虫子吗?
- 在应用程序B:
代码:
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缺陷。