Firstly, I have forcibly instantiate the LazyTableModel in the constructor of my managedBean otherwise, I get a ClassCastException when primefaces tries to cast ListDataModel to LazyDataModel.
Secondly, when the p:dataTable is populated using the LazyDataModel through my hibernate JPA query, no records are displayed initially. Page links are properly rendered and when I click one of the pageLinks the data shows up nicely. Not only that the firstPage link which initially displayed no data, when clicked again, nicely shows up the data. I don't know why I am getting this behaviour. Here is my code.
xhtml
Code: Select all
<p:dataTable id="donorTable" value="#{donorSearchBean.donors}" var="donor"
paginator="true" rows="10" dynamic="true" lazy="true"
emptyMessage="No Records to Display">
Code: Select all
public class DonorLazyDataModel extends LazyDataModel<Donor> {
public DonorLazyDataModel (QueryName queryName, String firstName, String lastName) {
super();
this.setPageSize(10);
try {
this.setRowCount((donorSearchService.
countDonorsByName(firstName, lastName, queryName)).intValue());
} catch(Throwable ex) {
ex.printStackTrace();
}
public List<Donor> load(int first, int pageSize, String sortField,
boolean sortOrder, Map filters) {
return donorSearchService.findDonorsByName(firstName,lastName, queryName, first);
}
Nirvan