Any CDI bean I inject in the implementation class of org.primefaces.model.LazyDataModel
, turns out null. The lazy model implementation class itself is a CDI @Named
bean with scope @javax.faces.bean.ViewScoped
. It looks like this:
@Named("myLazyModel")
@ViewScoped
Class MyLazyModel extends LazyDataModel implements Serializable {
public MyLazyModel() {
}
@Inject
AnotherCdiBeanClass injectedObj;
public AnotherCdiBeanClass getInjectedObj() {
return injectedObj;
}
public AnotherCdiBeanClass setInjectedObj(AnotherCdiBeanClass anotherCdiBeanClassObj) {
this.injectedObj = anotherCdiBeanClassObj;
}
public void someMethod() {
getInjectedObj(); // Its NULL, why?
}
}
I did get a warning in eclipse from Java while injecting in lazymodel implementation bean class. Warning was something like that the lazymodel class bean can not proxied by the container as it does not contain non-private no-arg constructor and the bean is not a normal scoped bean(something like that).
There is another problem, in the LazyDataModel implementation class, I have set the rowCount to the size of the actual data list's dynamic size (size after filtering in grid). But then after instantiating the lazymodel implementation class outside in some CDI bean gives me a rowCount of zero.
new MyLazyModel(actualDataList).getRowCount()
-> 0
Upon debugging I found it does contain the complete actual data list but rowCount is still zero.
I needed on the go rowCount
of the filtered rows as I type and filter them on a primefaces grid so that I can dynamically update an outputLabel with the currently filtered grid's rowCount value.
int currentRowCount = actualDataListInLazyModelClass.size();
I will be updating the outputLabel like this:
org.primefaces.context.RequestContext.getCurrentInstance.update("myForm:recordCountLabel");
But before that I need to set property of an injected bean (View's backing bean) with the rowCount value but the injected bean itself turns out null as said before.
getInjectedObj().setNoOfRecords(Integer.toString(currentRowCount));
// NULL POINTER because getInjectedObj() is null
Sorry if I have described things more or less due to limitations at my end.