Board index JavaServer Faces General Problem with LazyDataModel of DataTable

Problem with LazyDataModel of DataTable

Components, Ajax Framework, Utilities and More.


Posts: 1
Hi all,

I'm using PrimeFaces version 2.2, Apache Tomcat server 7.
I have a class as below, it's a portion of my whole source code. I expect to apply pagination with lazy loading in a data table.
private int offset = 0;
public CarSearchBean() {

   lazyModel = new LazyDataModel<Car>() {

       @Override
       public List<Car> load(int first, int pageSize, String sortField, boolean sortOrder,
          Map<String, String> filters) {
                lazyCar = new ArrayList<Car>();
                populateLazyCar(lazyCar, pageSize);

      return lazyCar;
       }

   };
   lazyModel.setRowCount(100000000);

    }

    public void populateLazyCar(List<Car> lazyCar, int size) {
   lazyCar = Cars.subList(this.offset, this.offset + size);
        this.offset = this.offset + size;
    }


The above code seems to be similar with the example in PrimeFaces showcase site. The Cars object contains data which are loaded from my database. In populateLazyCar(List<Car> lazyCar, int size) function, I split the Cars list into many parts which are corresponding to each page.

However, when executing it, an exception occurs :

SEVERE: java.lang.ClassCastException: javax.faces.model.ListDataModel cannot be cast to org.primefaces.model.LazyDataModel


I read many threads in this forum to find my own solution but I still get stuck on it.

I appreciate if you can help me solve this issue.


Posts: 4
I could not used LazyDataModel of DataTable and I wrote my custome code.

http://forum.primefaces.org/viewtopic.php?f=3&t=15505


Return to General