aspose file tools*
The moose likes Struts and the fly likes 10 enteries per page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "10 enteries per page?" Watch "10 enteries per page?" New topic
Author

10 enteries per page?

Priyanka Chopda
Ranch Hand

Joined: Jul 22, 2003
Posts: 112
Hello friends,
I'm having difficult time in figuring out how do I go in displaying 10 entries per page in struts and having "next" link to take to another 10 enteries?
right now I am trying to use pager tag lib (with no luck)!

Any help is appreciated
-PC
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Hello Sir,
This may help you
http://jsptags.com/tags/navigation/pager/pager-taglib-2.0.html#examples


Groovy
Priyanka Chopda
Ranch Hand

Joined: Jul 22, 2003
Posts: 112
Thanks a lot pradeep...I mean it!
-PC
Priyanka Chopda
Ranch Hand

Joined: Jul 22, 2003
Posts: 112
hi,
now I facing yet another problem. I'm using <logic:iterate> tag to fetech my records from database. If I were to use "for loop" atleast I can specify range i.e (for(i=0;i<=20;i++){display();} but in iterate how can I go on displaying only the first 10 records and then next 10 and so on...?
Can anybody help me here?
Thanks in advance
-PC
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

You will have to splilt your collection into sub-collections of size 10 each.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

BTW, what is wrong with the pager tag?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4757
    
    7

Originally posted by Priyanka Chopda:
I'm using <logic:iterate> tag to fetech my records from database.

I don't know if I'm understanding you correctly but why are you doing that? Normally, you fetch your records at one go, put the results in a collection and then iterate through them; you don't use the iterate to retrieve records. As for controlling the start and length, see the offset and length attributes, respectively, of the iterate tag.


Junilu - [How to Ask Questions] [How to Answer Questions]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Junilu ,Thanks for the info. I missed the offset attribute.
Priyanka Chopda
Ranch Hand

Joined: Jul 22, 2003
Posts: 112
Thanks Junilu & Pradeep,
I was not aware of offset and length attributes.
I guess now it shouldn't cause any problems.
-PC
Priyanka Chopda
Ranch Hand

Joined: Jul 22, 2003
Posts: 112
Plz bear with me...
here is my code...now I'am getting one entry per page by using offset and length attributes og iterate tag; but how do I see rest of the enteries??
Can someone elaborate more on this problem?
Thanks a ton in advance

-PC
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4757
    
    7

if you want 10 per page, use length="10". Alternatively, you can put an Integer that holds the pageLength value in a context collection (either application, session, or request). E.g.
// in your Java code:
request.getSession().setAttribute("pageLength", new Integer(10));
// in your tag:
<logic:iterate ... length="pageLength" ...>
The offset is the index into the underlying collection that you want to start the iteration. That would normally be calculated as something like
pageLength * (currentPage - 1);
Where currentPage is 1-based (1st page = 1, 2nd page = 2, etc.)
So, if your underlying collection had 35 entries and you displayed 10 per page, offset for page 1 would be 0, offset for page 2 would be 10, and offset for page 3 would be 20.
As with length, you can put an Integer into a context collection and use the attribute key as the value for offset, too.
// in code:
if (nextPageRequested()) {
currentPage++;
} else if (previousPageRequested()) {
currentPage--;
} ...
request.setAttribute("pageStartIndex", new Integer(offset());
...
// in JSP:
<logic:iterate ... length="pageLength" offset="pageStartIndex" ... >
Priyanka Chopda
Ranch Hand

Joined: Jul 22, 2003
Posts: 112
Bingo!!!its working fine now!
thanks junilu
bobby chaurasia
Ranch Hand

Joined: Mar 30, 2002
Posts: 84
Hi Priyanka,
Can you post your code as I have a requirement similar to yours except that instead of "next" or "previous" button I need to display a dynamic list of
page numbers eg :1 2 3 4 ( something like we have in java ranch forum) with each page to display 10 entries.
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 10 enteries per page?