PrimeFaces 数据表排序与排序过滤不适用于 JSF DataModel
我有 3 个测试 Web 应用程序,使用相同的模型和控制器,区别在于 JSF 会话管理 bean。
应用程序A和C使用JSF DataModel来检索项目: JPA 查询结果集返回一个 java LIST,然后将其包装在 ListDataModel 中。后者的值是 PrimeFaces dataTable 显示的项目。
应用程序B使用JavaLIST来检索项目: JPA 查询结果集返回一个 java List,它是 PrimeFaces 2.2.1 dataTable 显示的项目的值。
应用程序 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()));
}
}
}
提前感谢您的帮助。
I have 3 test web applications, using the same model and controllers, the difference is in JSF session managed beans.
The applications A and C use JSF DataModel to retrieve items :
A JPA Query result set returns a java LIST which is then wrapped in a ListDataModel. The value of this latter is being the items displayed by PrimeFaces dataTable.The application B uses Java LIST to retrieve items:
A JPA Query result set returns a java List which is being the value of items displayed by PrimeFaces 2.2.1 dataTable.
Sorting and filtering in application B are fully functional and fast, while in application A and C, they are deadly not.
I just want to mention that Filtering in Sorting of other Libraries like Richfaces, OpenFaces, works out of the box using this same code.
The problem also remains in PrimeFaces 3.0.0. Is this a bug?
- In App B :
Code:
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;
}
In App A:
Code:
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;
}
In App C:
Code:
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()));
}
}
}
Thank you in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是 PrimeFaces 的错误。我看到过一些关于使用数据模型时 DataTable 排序问题的讨论。以下是指向其跟踪器中的 PrimeFaces 缺陷之一的链接 。
This might be a PrimeFaces bug. I have seen some discussion about issues with DataTable sorting when a data model is used. Here is a link to one of the PrimeFaces defects in their tracker.