Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pagination Using Struts

 
satheesh krishnaswamy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can anyone help me as how to implement pagination using Struts.
I should not use any third party taglibs.I can only use Apache.

Please help me as it is pretty urgent.

Thanks in advance
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, there's no built-in function within Struts that handles pagination, but it wouldn't be that hard to create your own pagination bean. Here are some suggestions:

  • The bean should have properties for: total number of rows, rows per page, current page, total number of pages, and a collection containing all the rows.
  • When the page is first displayed, read all the rows and populate the appropriate bean properties and store the bean in the HTTP Session.
  • When The user requests next page, previous page, etc., have the bean calculate which data to display.

  •  
    Wes Sorensen
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Merrill's is a pretty good solution that will eliminate multiple database calls and would work well for a small site or a small rowset, but the scaling of it might be a factor.

    Say you're doing this for eBay and someone does a search for "computer". This returns say 15,000 rows. This could be a serious memory and performance problem - atleast on the first request where it loads the bean.

    I like the bean idea with the different fields, but I'd say take out the collection of rows, create a separate bean of the rows for that page - whatever the number of rows to display on the page is. So each request for the next page would result in a database query to load the bean, but it should be a small hit. This way, you don't max out your server memory after the 100 person does a query.

    The advantages to Merrill's solution is that you can do a single database lookup, store the results and basically just refresh the page. If you're not concerned with the memory or you know certain pages will have a small rowset, you can use that solution. Otherwise, consider something that will scale well no matter how many rows get returned.
     
    Mohd. Yakub
    Greenhorn
    Posts: 18
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi all,

    we can use struts-layout taglib ,to create much versatile interfaces including paging through pager tag.
    some more ,plz visit
    http://struts.application-servers.com/features/index.html
    Cheers,
    yakub
     
    Paul Lester
    Ranch Hand
    Posts: 40
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You might also want to look at JDBC 2.0's RowSet: http://java.sun.com/developer/Books/JDBCTutorial/chapter5.html
    I think that this would get you want you want in a very lightweight manner; however, you'd have to make sure that your DB vendor supports this extension. I know that Oracle supports.

    Regards,

    Paul
     
    michelle Wang
    Ranch Hand
    Posts: 65
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I use this tag lib, quite easy to implement:

    http://jsptags.com/tags/navigation/pager/index.jsp
     
    jakes vandenberg
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by michelle Wang:
    I use this tag lib, quite easy to implement:

    http://jsptags.com/tags/navigation/pager/index.jsp


    Hi Michelle
    how do I specify my bean that I previously used in an iterate tag?
    do you have an example jsp to share?

    Thanks
    jakes
     
    Naseem Khan
    Ranch Hand
    Posts: 809
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well What I think is pagination should be done at database level not at the presentation tier. Why you are having that much data in memory which you don't want to show on the first page.

    Suppose you have 3000 rows in database. With just say 100 different threads accessing you application, there will be 3000*100 no. of rows which you will have in memory in form of java objects.

    This link might help ...

    [Pagination problem]

    Regards

    Naseem
    [ July 13, 2006: Message edited by: Naseem Khan ]
     
    Jiya Khan
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    Hi,

    I have ArrayList of valueobject Things and need to display the details things name things price etc.. in some table structure..


    can any one guide me how to achieve pagiantion for ArrayList?
    code is as follows
    <% List defaultlist= new ArrayList();
    if(request.getAttribute("DefaultThings")!= null) {
    defaultlist = (List)request.getAttribute("DefaultThings");
    }

    ListIterator iter1 = defaultlist.listIterator();
    String name= new String();
    int coun1t=0;
    while (iter1.hasNext()) {
    Things th1= (Things)iter1.next();
    name= th1.getThingsName();
    %>

    <table><tr><td>
    <%=name%>

    </td></tr></table>
     
    Ankit Garg
    Sheriff
    Posts: 9521
    22
    Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Jiya please Dont Wake The Zombies, this thread is 3 years old, start a new topic for your question by clicking on ...
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic