简体   繁体   English

PrimeFaces DataTable排序和过滤不适用于JSF DataModel

[英]PrimeFaces DataTable Sorting & Filtering don't work with JSF DataModel

I have 3 test web applications, using the same model and controllers, the difference is in JSF session managed beans. 我有3个测试Web应用程序,使用相同的模型和控制器,不同之处在于JSF会话托管bean。

  • 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. 应用程序AC使用JSF DataModel检索项目:JPA查询结果集返回一个Java LIST,然后将其包装在ListDataModel中。 The value of this latter is being the items displayed by PrimeFaces dataTable . 后者的值是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. 应用程序B使用Java LIST检索项目:JPA查询结果集返回一个Java List,它是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. 应用程序B中的排序和筛选功能齐全且快速,而在应用程序A和C中则不是致命的。

I just want to mention that Filtering in Sorting of other Libraries like Richfaces, OpenFaces, works out of the box using this same code. 我只想提到在排序其他库(如Richfaces,OpenFaces)中进行过滤时,可以使用相同的代码直接使用。

The problem also remains in PrimeFaces 3.0.0. 该问题也仍然存在于PrimeFaces 3.0.0中。 Is this a bug? 这是错误吗?

  • In App B : 在应用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: 在应用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: 在应用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. 预先感谢您的帮助。

This might be a PrimeFaces bug. 这可能是PrimeFaces错误。 I have seen some discussion about issues with DataTable sorting when a data model is used. 我已经看到了有关使用数据模型时DataTable排序问题的一些讨论。 Here is a link to one of the PrimeFaces defects in their tracker . 这是指向其跟踪器中PrimeFaces缺陷之一的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM