Hi Eric,
I'm not sure about a "right way" to manage the PaginatedList once we
get it out of iBATIS; I suppose it depends on the application using
it. Thus, I think some may consider this thread to be slightly off
topic, but I agree that it would be nice to have some examples up on
the wiki.
For my Struts web app, I'm keeping the PaginatedList in session scope
(the page limit is 25, so I don't think this will cause problems).
I'm assuming you're doing the same, since the only other alternative I
can think of is to somehow execute the exact same query again, get a
brand new PaginatedList, then manipulate the page accordingly before
sending it the the View layer.
In my JSPs, I'm doing the same as you but with Struts tags: checking
the isXXXXPageAvailable() methods to provide "previous" and "next"
links.
However, I have an idea to remove or cut down on the size of your
scriplet. Would this work with the c tags?
<c:out value="${mystat.count + pageScope.sfsaved.pageIndex *
pageScope.sfsaved.pageSize }" />
<c:choose>
<c:when test="${pageScope.sfsaved.previousPageAvailable}">
<input type="submit" name="event" value="<bean:message
key="button.Water_Reports.previousSet" />" />
</c:when>
<c:otherwise>
<input type="submit" name="event" value="<bean:message
key="button.Water_Reports.previousSet" />" disabled="disabled" />
</c:otherwise>
</c:choose>
The difference is drilling down through the "sfsaved" variable instead
of explicitly setting its properties into PageContext.
At risk of straying further off topic, how about this to take the
clean-up a bit further with your Previous button:
<% String prevDisabled = "disabled=\"disabled\""; %>
<c:choose>
<c:when test="${pageScope.sfsaved.previousPageAvailable}">
<% prevDisabled = ""; %>
</c:when>
</c:choose>
<input type="submit" name="event" <%=prevDisabled%>
value="<bean:message key="button.Water_Reports.previousSet" />"
/>
This makes it obvious that your submit button will always be
displayed; it's just a matter of whether it's disabled or not. The
"downside", if it's necessary to label it as such, is that it's not
completely tag-based. But, your button will show in the "design" mode
of JSP editors.
Ted