xrcwrn
xrcwrn

Reputation: 5327

How to iterate int value in specific range in struts2

I am implementing pagination, for that i have to iterate from 1 to totalPages

in action i have taken variable totalPages which contains total no of pages( like 10, 20,30 etc)

private int totalPages;

in jsp i want to iterate 1 to totalPages using

Upvotes: 0

Views: 411

Answers (2)

coding_idiot
coding_idiot

Reputation: 13734

I think you should do something like this :

  1. Every page no. should be a link which should contain some parameter which helps the action in determining what page of records is to be shown.

page link should be like

<a href="<s:url action="getpage">
   <s:param name="pageno" value="4"/>
</s:url>">Page 4</a>

Upvotes: 1

Umesh Awasthi
Umesh Awasthi

Reputation: 23587

i am not sure what your exact requirement, but for pagination you have to place your logic in your action class which includes

  1. Total Number of records.
  2. Number of records you want to show per pages.

based on above 2 values you will get how many pages you have total.All you need to show them in your jsp and based on the page number you have to calculate the starting record number and the number of record you will fetch.

for showing pages on JSP you have to decide what format you want to have and need to place some sort of if and else statements.

there is nothing like specific to Struts2 and its a generic logic, all dependents upon how you want to implement.

since i believe you will not fetch all the record in one go and will fetch them per page

Upvotes: 1

Related Questions