Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Paging without JSTL or any other 3rd party tag

 
jakes vandenberg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Has anybody done paging by just using the logic:iterate tag and programmatically changing the offset attribute to go to the next or previous page? Do you have any examples?

I did use the pager taglib from jsptags.com, but then was informed (from the powers above) that I'm not allowed to use it, and that I should try and do it with the iterate tag.

Thanks
jv
 
Dhulipalla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using display tag, its a cool one

http://displaytag.sourceforge.net/11/
 
jakes vandenberg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dhulipalla, but unfortunately I'm not allowed to use any 3rd party tags. I know it sucks, but that is something I have to deal with now. So if anyone out here has an example to share or can point me in the direction how to use it to manipulate the offset attribute on the logic iterate tag to do paging, it will be greatly appreciated.

Thanks.
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use your action to control which results are sent to the screen. Then the paging hyperlinks would look like this:

<a href="/myAction.do?offset=0&length=10">Page 1</a>
<a href="/myAction.do?offset=10&length=10">Page 2</a>

More specifically it would look like this:

<logic:iterate name="MyForm" property="resultList" id="currentResult">
<bean:write name="currentResult" property="description"><br>
</logic:iterate>

<logic:iterate name="MyForm" property="numPages" id="currentPage">
<a href="<html:rewrite page="/myAction"/>?offset=<bean:write name="currentPage">&length=<bean:write name="MyForm" property="length"/>">Page <bean:write name="currentPage"/></a><br>
</logic:iterate>

This is assuming that the resultList is put in something called MyForm. That MyForm also has a list of numPages where each element in the collection is a page number. It also assumes there is a length property in the Form. There are some better ways to do it, but this should get you started.
 
jakes vandenberg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dom. I'll work with that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic