Question

I'm trying to use the primefaces LazyDataModel for a tabelaric view in JSF, the problem is that I'm unable to inject anything into the class. I always get null fot the injected object.

For example I'm injecting

@PersistenceContext(unitName = "domainDS")
private EntityManager em;

or an EJB

@EJB
OrganizationHandler orgHandler;

but I get null for both of them.

The whole lazy datamodel class

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

import si.arctur.controller.OrganizationHandler;
import si.arctur.model.Organization;

@Named
@Stateless
public class LazyOrganizationDataModel extends LazyDataModel<Organization> implements Serializable {

private static final long serialVersionUID = 675394666656356734L;

@PersistenceContext(unitName = "domainDS")
private EntityManager em;

@EJB
OrganizationHandler orgHandler;

public LazyOrganizationDataModel() {
    super();
}

@SuppressWarnings("unchecked")
@Override
public List<Organization> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {

    List<Organization> data = orgHandler.selectOrganizatoins(first, pageSize, sortField, "asc", filters);
    //row count
    this.setRowCount(data.size());

    return data;
    }
}
Was it helpful?

Solution

You're probably not injecting the lazy data model. Based on their examples, they show someone instantiating it. You should instead get a reference via CDI to the bean.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top