jsf - Getting properties of <p:dataScroller> in backing bean -
how can following properties of <p:datascroller>
in backing bean?
- page index (on page in pagination on)
- page count
- page index
- first row index
- last row index
i tried component binding, returns null
.
the <p:datascroller>
has ton of issues, if want these properties, have them indirectly, because if don't use lazydatamodel, datascroller fetches data @ once , goes away stuff, never calling managedbean.
use lazy load model. have quick implementation of org.primefaces.model.lazydatamodel
around 20 lines of code. create method on managedbean returns sublist requested; inside managed bean fetch values want.
import java.util.list; import java.util.map; import org.primefaces.model.lazydatamodel; import org.primefaces.model.sortorder; class msgloglazymodel extends lazydatamodel<yourpojo> { private static final long serialversionuid = 1l; private managedbean mb; public msgloglazymodel(managedbean mb) { this.mb = mb; } @override public list<yourpojo> load(int first, int pagesize, string sortfield, sortorder sortorder, map<string, object> filters) { return mb.loaditens(first, pagesize, sortorder, filters); } }
yourpojo should object passing datascroller display.
assuming items have display stored in mb property
private list<yourpojo> mylist;
now on mb.loaditens()
capture:
- page index (on page in pagination on)
int pageindex = first / pagesize;
- page count
// have round because last page have less pagesize itens
int pagecount = (int) math.ceil(mylist.size() / new double(pagesize));
- page index
you repeating yourself.
- first row index
i assume want first row of chunk returned. first
parameter. since datascroller not have pagination...
- last row index
// maybe list has ended. take safe path...
int lastrow = math.min(mylist.size(), first + pagesize)
Comments
Post a Comment