jsf - JSF2 + Primefaces : DataTable lazy loading issue -
i guess, java code proper, records not showing on datatable.
please check below code. dont know made mistake.
.xhtml
<p:datatable value="#{userdetaillist.userdatalist}" var="user" rows="5" paginator="true" lazy="true" paginatortemplate="{rowsperpagedropdown} {firstpagelink} {previouspagelink} {currentpagereport} {nextpagelink} {lastpagelink}"> <p:column headertext="no"> <h:outputtext value="#{user.id}"></h:outputtext> </p:column> <p:column headertext="user name"> <h:outputtext value="#{user.username}"></h:outputtext> </p:column> </p:datatable>
.java
@postconstruct public void init(){ // +getter , setter userdatalist = new lazydatamodel<userdetail>(){ private static final long serialversionuid = 1l; @override public list<userdetail> load(int first, int pagesize, string sortfield, sortorder sortorder, map<string, string> filters) { return lazydatamodelcom.getresultlist(first, pagesize, sortfield, sortorder, filters); } }; }
getresultlist
public list<userdetail> getresultlist(int first, int pagesize, string sortfield, sortorder sortorder, map<string, string> filters) { session session = hibernateutils.getsession(); criteria criteria = session.createcriteria(userdetail.class); criteria.addorder(order.asc("id")); (map.entry<string, string> entry : filters.entryset()) { if (entry.getvalue() != null) { criteria.add(restrictions.ilike("id", "%" + entry.getvalue() + "%")); } } criteria.setmaxresults(pagesize); criteria.setfirstresult(first); return criteria.list(); }
getresultlist method return proper value, debug it. think problem in userdatalist.
your lazydatamodel
implementation not setting rowcount. should like:
public void init(){ // +getter , setter userdatalist = new lazydatamodel<userdetail>(){ private static final long serialversionuid = 1l; @override public list<userdetail> load(int first, int pagesize, string sortfield, sortorder sortorder, map<string, string> filters) { userdatalist.setrowcount(...); return lazydatamodelcom.getresultlist(first, pagesize, sortfield, sortorder, filters); } }; userdatalist.setrowcount(...); }
pay attention rowcount
feeded number of rows before pagination after filtering.
see this answer containing working example (with difference uses jpa criteria api instead of hibernate criteria):
Comments
Post a Comment