【问题标题】:PrimeFaces DataTable Sorting & Filtering don't work with JSF DataModelPrimeFaces DataTable 排序和过滤不适用于 JSF DataModel
【发布时间】:2011-09-22 18:48:19
【问题描述】:

我有 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 中也存在该问题。这是一个错误吗?

  • 在应用 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()));
            }
        }
    }

提前感谢您的帮助。

【问题讨论】:

    标签: jsf primefaces datamodel


    【解决方案1】:

    这可能是 PrimeFaces 错误。在使用数据模型时,我看到了一些关于 DataTable 排序问题的讨论。这是link to one of the PrimeFaces defects in their tracker。

    【讨论】:

    • 我刚刚在论坛里得到了同样的答案!实际上 ListDataModel 的排序已在上一个快照 3.0M2 中修复。我也在为过滤创建一张票。谢谢吉姆
    • 感谢您对最新快照的提醒。我还没有使用 ListDataModel,但我将来可能会需要它。
    猜你喜欢
    • 2012-10-01
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    • 2011-09-15
    • 2013-08-21
    • 2014-10-04
    • 1970-01-01
    相关资源
    最近更新 更多