| Author |
Pagination Using Struts
|
satheesh krishnaswamy
Ranch Hand
Joined: Mar 17, 2004
Posts: 137
|
|
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
Joined: Feb 15, 2005
Posts: 4864
|
|
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.
|
Merrill
Consultant, Sima Solutions
|
 |
Wes Sorensen
Greenhorn
Joined: Dec 02, 2005
Posts: 13
|
|
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
Joined: Nov 25, 2005
Posts: 18
|
|
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
Joined: Dec 27, 2002
Posts: 40
|
|
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
|
Where Photography meets vision.<br /><a href="http://www.photogravision.com" target="_blank" rel="nofollow">http://www.photogravision.com</a><br />Please stop by!<br /> <br />SCJP,SCWCD,SCJD,SCEA
|
 |
michelle Wang
Ranch Hand
Joined: Jan 12, 2004
Posts: 65
|
|
I use this tag lib, quite easy to implement: http://jsptags.com/tags/navigation/pager/index.jsp
|
michelle Wang <br />SCJP 1.4
|
 |
jakes vandenberg
Greenhorn
Joined: Nov 05, 2004
Posts: 14
|
|
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
Joined: Apr 25, 2005
Posts: 809
|
|
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 ]
|
Asking Smart Questions FAQ - How To Put Your Code In Code Tags
|
 |
Jiya Khan
Greenhorn
Joined: Jul 07, 2009
Posts: 3
|
|
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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Jiya please Dont Wake The Zombies, this thread is 3 years old, start a new topic for your question by clicking on ...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
 |
|
|
subject: Pagination Using Struts
|
|
|