Board index JavaServer Faces General ListDataModel cannot be cast to LazyDataModel

ListDataModel cannot be cast to LazyDataModel

Components, Ajax Framework, Utilities and More.

Posts: 69

I tried to implement sorting and filtering for my datatable, but I got this error stop me from going further.

Here is the full trace:

java.lang.ClassCastException: javax.faces.model.ListDataModel cannot be cast to org.primefaces.model.LazyDataModel
   at org.primefaces.component.datatable.DataTable.loadLazyData(
   at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(
   at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(
   at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(
   at javax.faces.component.UIComponentBase.encodeEnd(
   at javax.faces.component.UIComponent.encodeAll(
   at javax.faces.render.Renderer.encodeChildren(
   at javax.faces.component.UIComponentBase.encodeChildren(
   at javax.faces.component.UIComponent.encodeAll(
   at javax.faces.component.UIComponent.encodeAll(
   at javax.faces.component.UIComponent.encodeAll(
   at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(
   at com.sun.faces.application.view.MultiViewHandler.renderView(
   at com.sun.faces.lifecycle.RenderResponsePhase.execute(
   at com.sun.faces.lifecycle.Phase.doPhase(
   at com.sun.faces.lifecycle.LifecycleImpl.render(
   at javax.faces.webapp.FacesServlet.service(
   at org.apache.catalina.core.StandardWrapper.service(
   at org.apache.catalina.core.StandardWrapperValve.invoke(
   at org.apache.catalina.core.StandardContextValve.invoke(
   at org.apache.catalina.core.StandardPipeline.invoke(
   at com.sun.enterprise.web.WebPipeline.invoke(
   at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(
   at org.apache.catalina.core.StandardHostValve.invoke(
   at org.apache.catalina.connector.CoyoteAdapter.doService(
   at org.apache.catalina.connector.CoyoteAdapter.service(
   at com.sun.grizzly.http.ProcessorTask.invokeAdapter(
   at com.sun.grizzly.http.ProcessorTask.doProcess(
   at com.sun.grizzly.http.ProcessorTask.process(
   at com.sun.grizzly.http.DefaultProtocolFilter.execute(
   at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(
   at com.sun.grizzly.DefaultProtocolChain.execute(
   at com.sun.grizzly.DefaultProtocolChain.execute(
   at com.sun.grizzly.http.HttpProtocolChain.execute(
   at com.sun.grizzly.ProtocolChainContextTask.doCall(
   at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(
   at com.sun.grizzly.util.AbstractThreadPool$

Here is the java code:

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

package com.customerapp.web;

import com.customerapp.ejb.CustomerSessionBean;
import com.customerapp.entity.Customer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.model.LazyDataModel;

 * @author sam
public class CustomerMBean

    private CustomerSessionBean customerSessionBean;
    private Customer customer;
    private final static Logger logger = Logger.getLogger(CustomerMBean.class.getName());

    private LazyDataModel<Customer> lazyModel;

    public CustomerMBean()
        lazyModel = new LazyDataModel<Customer>() {

          * Dummy implementation of loading a certain segment of data.
          * In a real application, this method should load data from a datasource
         public List<Customer> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String,String> filters) {
            logger.log(Level.INFO, "Loading the lazy car data between {0} and {1}", new Object[]{first, (first+pageSize)});

                //Sorting and Filtering information are not used for demo purposes just random dummy data is returned

                               // customerSessionBean.setMaxResults(pageSize);
                              //  return customerSessionBean.getResultList();
                                    return  null;

    public LazyDataModel<Customer> getLazyModel() {
        return lazyModel;
    public void setLazyModel(LazyDataModel<Customer> lazyModel) {
        this.lazyModel = lazyModel;

     * Returns list of customer objects to be displayed in the data table
     * @return
    public List<Customer> getCustomers()
        return customerSessionBean.retrieve();

     * Returns the selected Customer object
     * @return
    public Customer getDetails()
        //Can either do this for simplicity or fetch the details again from the
        //database using the Customer ID
        return customer;

     * Action handler - user selects a customer record from the list
     * (data table) to view/edit
     * @param customer
     * @return
    public String showDetails(Customer customer)
        this.customer = customer;
        return "DETAILS";

     * Action handler - update the changes in the Customer object to the
     * database
     * @return
    public String update()
        customer = customerSessionBean.update(customer);
        return "SAVED";

     * Action handler - goes to the Customer listing page
     * @return
    public String list()
        return "LIST";

PF 2.2RC2, Glassfish v3, Netbeans 6.9.1

Primefaces 2.2.1, JBOSS 6.0.0.Final, JDK1.6

Return to General