Reputation: 242
I am calculating the number of pages in a search screen in an Action class. I need to iterate from 1 to to display page numbers with links, and I can't find a way to do this with <s:iterator>
The java equivalent code will be, Please let me know where there is a way to achieve this in a JSP with struts 2.0 tags.
for ( int i = 1; i <= pageCount; i++ ) {
// print page no
}
Thanks in advance.
Upvotes: 0
Views: 1412
Reputation: 160191
http://struts.apache.org/2.x/docs/iterator.html
Use the "begin"
and "end"
attributes of the <s:iterator>
tag for easy-to-read loops.
You can also play OGNL games, like:
<s:iterator status="stat" value="(5).{ #this }">
which will loop five times.
Values can come from an action property as normal.
Upvotes: 1
Reputation: 23587
For using a look in the JSP side of your S2 application you have the way to use Struts2 Iterator tag.
This iterator tag take a collection as input source of iteration. If you are using S2 version 2.1.7 or higher, you can take the advantage of begin, end and step attributes.All you need to have a collection in your Action class with its getter and setters and in your JP you have to do something like
<s:iterator value="days">
<p>day is: <s:property/></p>
</s:iterator>
For details refer to the tag documentation
You are free to use S2 if tag inside the iterator tag to place various conditions as per your requirements
Upvotes: 1