displaytag - Display tag pagination problem -
in display tag used pagination feature ,when want see list of 15 rows display tag featch rows database. every time when click on pagination number,it featch of rows db.bcoz of slow performace of application.
i want in display tag when want see 15 rows display tag fetch 15 rows db not entire db rows. plz me if 1 knows.
you have use external pagination feature. first, specify in html tag you're using external pagination. , create object implements org.displaytag.pagination.paginatedlist. finally, have implement dao makes query 15 rows , returns paginatedlist.
1) jsp this
<display:table name="command" sort="external" partiallist="true" size="${command.fulllistsize}" pagesize="${command.objectsperpage}"> <display:column property="name" title="name"/> ... </display:table>
note specified sort external.
2) org.displaytag.pagination.paginatedlist implementation.
public class paginatedlistimpl<t> implements paginatedlist{ private int fulllistsize; private int objectsperpage; private int pagenumber; private string searchid; private string sortcriterion; private sortorderenum sortdirection; private list<t> list; //getters , setters ... }
3) dao implementation sample using hibernate. can jdbc or make sure you're making right query 15 rows in proper order , return paginatedlistimpl object.
@suppresswarnings("unchecked") public paginatedlistimpl<t> getpaginatedlist(paginatedlistimpl paginatedlist) { int pagenum = paginatedlist.getpagenumber(); final int objectsperpage = paginatedlist.getobjectsperpage(); final int firstresult = objectsperpage * pagenum; string sortordercriterion = pagiantedlist.getsortordercriterion(); string sortorder = paginatedlist.getsortorder string classname = type.getname().substring(type.getname().lastindexof(".") + 1); final stringbuilder fromclause = new stringbuilder("from " + classname + " " + alias); string orderbyclause = new stringbuilder(" order ").append(sortcriterion).append(" ").append(sortdirection); final string hql = new stringbuilder().append(fromclause).append(orderclause).tostring(); list<t> resultlist = gethibernatetemplate().executefind(new hibernatecallback() { public object doinhibernate(session session) throws hibernateexception, sqlexception { return session.createquery(hql) .setfirstresult(firstresult) .setmaxresults(objectsperpage) .list(); } }); long count = (long)gethibernatetemplate().execute(new hibernatecallback() { public object doinhibernate(session session) throws hibernateexception, sqlexception { return session.createquery("select count(*) " + fromclause).uniqueresult(); } }); paginatedlist.setfulllistsize(count.intvalue()); paginatedlist.setlist(resultlist); paginatedlist.setpagenumber(pagenum+1); paginatedlist.setobjectsperpage(objectsperpage); return paginatedlist; }
Comments
Post a Comment