Loading... Cancel

iBatis PaginatedList and pagination R

October 25th, 2006

iBatis has very good pagination support. every query can be limited by max number of rows and scrollable.
for example i have executed “queryForPaginatedList( “queryName”, domainObject, MAX_ROWS ) “;
iBatis PaginatedList class is extension of “java.util.List” class. so you can generally use it as collection object.
following methods are added to PaginatedList class:

    int getPageSize();

page size is current size of list (list.size() == MAX_ROWS)

    boolean isFirstPage();

if page offset is 0 no “nextPage” is invoked (default state)

    boolean isMiddlePage();

if between last and first offset (though did not use it, just assumption)

   boolean isLastPage();

if page offset == total available page

boolean isNextPageAvailable();

if current offset is not the last offset

    boolean isPreviousPageAvailable();

if current offset is not set to ‘0′ i mean already (nextPage(…)) invoked.

    boolean nextPage();

hit database(or cache) to load next MAX_ROWS number of items

    boolean previousPage();

hit database(or cache) to load rows from certain range from current state to one step backward.

    void gotoPage(int i);

move forcefully to certain page by specified offset

int getPageIndex();

return current page index(offset) number

How to paginate through your records?:

1. let’s think some one accessed your controller, you performed some retrieval task, and stored this “PaginatedList” object into session context.
2. when user request for  “next” page. you just load your object from session and invoke “pgList.nextPage()”
3. when user request for “back/previous” page you just load your object from session and invoke “pgList.previousPage()”
4. and set again in session context.
5. access from view .. and render your desire UI…
regards and Eid Mubarak!!!