DataTable Sorting & Filtering don't work with JSF DataModel

UI Components for JSF
Post Reply
User avatar
mediterran81
Posts: 29
Joined: 22 Mar 2011, 12:14
Location: France
Contact:

25 Jun 2011, 23:11

I have 3 test web applications, using the same model and controllers, the difference is in JSF session managed beans.

- The application 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.

Along with Export capabilities, sorting and filtering, resistance to PrimeFaces is futile, no argue about it. Yet, those three latter should be fully functional and that is what I am struggling to do. Probably something wrong in the code of my web apps!
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: Select all

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: Select all

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: Select all

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.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

26 Jun 2011, 12:27

3.0.M2 supports ListDataModel sorting, you can create an enhancement request to support datamodel filtering as well.

http://code.google.com/p/primefaces/iss ... il?id=1435

User avatar
mediterran81
Posts: 29
Joined: 22 Mar 2011, 12:14
Location: France
Contact:

26 Jun 2011, 15:56

Thanks for you reply. Issue created. Regards.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 35 guests