0

I am using pagination in my project. But my pagination index number is not properly set. Like:

First page

  • John ...
  • smith ...
  • Doe ...

Second page

  • New account ...
  • New account2 ...
  • New account 3 ...

I want the second page like this:

  • New account ...
  • New account 2 ...
  • New account 3 ...

I use iterator to do this.

<s:if test="#request.userList.size > 0">
                <s:iterator value="#request.userList" var="user" status="status">
                    <tr>
                        <th><s:property value="#status.count" />
                        </th>
                        <td><s:property value="#user.userName" />
                        </td>
                        <td><s:property value="#user.userRole" />
                        </td>
                        <td><s:property value="#user.userEmail" />
                        </td>
                        <s:if test="#session.user.userRole.equalsIgnoreCase('admin')">
                            <td><a
                                href=<s:url value="/updateUser?id=%{#user.userId}" />>Edit</a>/
                                <a href=<s:url value="/deleteUser?id=%{#user.userId}" />>
                                    Delete</a>/ <a
                                href=<s:url value="/viewProfile?id=%{#user.userId}" />>
                                    View</a>
                            </td>
                        </s:if>
                    </tr>
                </s:iterator>
            </s:if>

I have to calculate index like :

index = #status.count + ((pageNumber-1) * pageSize);

How could I do this? I could not access value from struts (#status.count) in jsp code, pls.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Aung Thet
  • 3,051
  • 3
  • 13
  • 18
  • How about using grid's? You can try the [Struts2 Jquery Grid](http://stackoverflow.com/questions/21927173/grid-in-struts2-using-struts2-jquery-grid-plugin) for pagination, sort, add, edit, delete the record as well. – Vinoth Krishnan Feb 23 '16 at 06:39
  • Did you try `#stat.count`? – Roman C Feb 23 '16 at 08:18
  • use `status="stat"` in s:iterator tag and use `#stat.count` as already said by @RomanC – Kunal Surana Feb 23 '16 at 08:48
  • It's not clear what you want: can you explain ? The second page you have and the second page you want are identical, except for the 2 not having a leading space ( `account 2` vs `account2`) – Andrea Ligios Feb 23 '16 at 10:27

1 Answers1

0

I would use index property of struts2 iterator:

%{#status.index}

You can find more information:

To access the index value of struts iterator in scriptlet array index

https://struts.apache.org/maven/struts2-core/apidocs/org/apache/struts2/views/jsp/IteratorStatus.html

Community
  • 1
  • 1