• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to do paging in struts

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to implement paging in my struts application. Does anyone know any existing one? or if someone know please help me and show me how.
thanks a lot everyone
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean "paging", as in a form that spans multiple pages like a wizard, or something else?
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are looking for a pager to display list in multiple pages and keep link to them (like a 1 2 3 next previous), visit http://jsptags.com/tags/navigation/pager/pager-taglib-1.1.html
They have a very good tag library and very easy to implement
Hope this helps.
 
Jay Richards
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My data/records will be coming from a database... i want to implement a next-previos button to browse to the result...
 
Jay Richards
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the records is in arraylist that i put on the session.
any idea anyone?
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The <logic:iterate> tag has "offset" and "length" attributes that might be useful. Let's say you wanted a max number of "maxRecords" per page:
<logic:iterate id="myRecord" name="myList" offset="<%= (pageNumber - 1) * maxRecords %>" length="<%= maxRecords %>" />
HTH
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After re-reading your question, let me expand on my previous answer.
One thing you could do is store the current page number in the request and have your Next and Previous buttons link to a url such as /do/viewResults?page=[currentPage +/- 1]. If it's the first or the last page simply disable the appropriate button when rendering the page.
 
Jay Richards
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
will the variable i used like
page and max
for this example url ".do?page=1?max=10"
be available in my bean tags?
thanks
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jay Richards:
will the variable i used like
page and max
for this example url ".do?page=1?max=10"
be available in my bean tags?
thanks


If in your action you do this:

If you need to access "pageNumber" as a scripting variable, you would have to use <bean:define>. Given the above code, the following code will output "4 5 4", just to give you some ideas of the different ways you may access these objects.
 
Mary White
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jay,
Don't reinvent the wheel, go to http://jsptags.com/tags/navigation/pager/pager-taglib-1.1.html
Their pager is really good.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link. It's good to know that's out there.
While I absolutely agree with you as far as not re-inventing the wheel, imho this is one of those things that even if the tags are used, one should acquire the skillset necessary to implement it oneself if needed. It's a nice academic exercise if nothing else.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're into Design Patterns, Check out the Fast Lane Reader J2EE design pattern at java.sun.com.
I believe it's at http://java.sun.com/blueprints/patterns/FastLaneReader.html.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic