我正在尝试使用primefaces LazyDataModel作为JSF中的tabelaric视图,问题是我无法向类中注入任何东西。我总是在注入的对象上得到null。
例如我正在注射
@PersistenceContext(unitName = "domainDS")
private EntityManager em;
或EJB
@EJB
OrganizationHandler orgHandler;
但我对他们两个都是空的。
整个懒惰的数据模型类
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;
}
}
答案 0 :(得分:1)
您可能没有注入惰性数据模型。根据他们的例子,他们显示有人实例化它。您应该通过CDI获取对bean的引用。