• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display N records per page

 
N Nanda
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all... I am using Struts and JSP for a project. I want to display a fixed no. of rows (retrieved from database) in a page. Can anyone please help me ? Its an urgency.

Thank u all in advance...
 
Manish Mehta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.displaytag.org/example-paging.jsp

I haven't made it to use it yet, but it seems this would work.

-- Manish
 
Srinivas Genji
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Nanda,
If you`re using MySql database,limit will solve your problem.
I`ve got a logic independent of any language,which display N number of records per page

if(!current_page)current_page=1;

Total_count = no of rows obtained from the database query.
No_of_records_per_page=10(N)
last_record = current_page * No_of_records_per_page
first_record= last_record - No_of_records_per_page

if(last_record>total_count)last_record=total_count;

for(int i=first_record;i<last_record;i++){
-------query goes here---
}

Hope this will give you an brief idea,if not hit me back.
 
Pankaj Narang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi nanada

I think you want to show the records same as google does after you perform a search, The display taglib is the best option it reduces your work by 85% as it has inbuilt iterator in it and hence does the paging perfectly,

see the examples of display taglib in the aboce links you will get the clear idea.

Best Regards
Pankaj
 
Ram Kumar Subramaniam
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure this is not a suggestion to do it fast. Have a look at and
Value List Handler. You will need to customize it a bit. Just have a look at the concept and implement it yourself.

Have a look at the following

1.) Page.java
2.) GenericCatalogDAO. The method - getItems(String productID, int start, int count, Locale locale)

3.) forget the rest if you need to implement code fast.Fast Lane Reader
[ June 28, 2004: Message edited by: Ram Kumar Subramaniam ]
 
Ram Kumar Subramaniam
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you might want to change the implementation of the method getStartOfPreviousPage() in Page.java

Am not sure if this would give the correct previous result.

I think this would be better

Math.max(start-count, 0);//where count is the number of records you want to retrive per set or page.
 
N Nanda
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Friends..... but let me explain my situation a little more and let me tell you where i am facing the problem.

since i am using struts, so there is no direct interaction of my JSP page and database. i am using a separate DAO class which has a method like getAllCourses(...) which returns an ArrayList object. Now my JSP page is given that ArrayList object which it iterates to display the records. I can too use some counter on this ArrayList to diplay say 10 records per page.

Now when I'll update (also delete) a record, I'll update it in the database. So it cannot be reflected in the same ArrayList object. isn't it ? Now my question is how I should make that updation be reflected in that ArrayList object.

Thanx all in advance.
 
Hardy Chou
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about if you have let's say 5000 records. Would displaytag or value list handler pattern can overcome it?
 
Pankaj Narang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

Any no of records can be iterated in pages usong display taglib, thee are many option as said above you can use any one of them

Best Regards
Pankaj
 
Joe Pardi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, check out the grid component at http://www.dotjonline.com/taglib/grid.jsp
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!