I use a JavaBean and JavaScript as follows:
<jsp:useBean id="mybean" class="MyClass" scope="session" > <%! int i = 0; %>
</jsp:useBean>
then some JSP and HTML...
<table>
<% int rowCount = 0;
int startRow = 0;
String start = (String) request.getParameter("start");
startRow = new Integer(start).intValue();
mybean.setStartRow(startRow);
while (rowCount < 100 && mybean.nextRow() > 0) {
%>
then I output the table rows..., then:
<% i++;
rowCount++;
}
%>
</table>
then I have a Back and Next button pair, and this is where the problem is:
<a href=http://www.webdeveloper.com/forum/archive/index.php/"<%= request.getContextPath() %>/jsp/this.jsp?start=<%= (startRow > 99) ? startRow - 100 : 0 %>"
onclick="javascript:<% i = i - startRow; %> return true;">
Back</a>
<a href="<%= request.getContextPath() %>/jsp/this.jsp?start=<%= mybean.getCurrentRow() %>">
Next</a>
The problem is a NullPointerException with setStartRow, but if I take out the onclick code, it almost works; it just doesn't decrement the i counter when I go back.
How do you make this work so the i counter gets decremented when you hit the back button?
Thx
<jsp:useBean id="mybean" class="MyClass" scope="session" > <%! int i = 0; %>
</jsp:useBean>
then some JSP and HTML...
<table>
<% int rowCount = 0;
int startRow = 0;
String start = (String) request.getParameter("start");
startRow = new Integer(start).intValue();
mybean.setStartRow(startRow);
while (rowCount < 100 && mybean.nextRow() > 0) {
%>
then I output the table rows..., then:
<% i++;
rowCount++;
}
%>
</table>
then I have a Back and Next button pair, and this is where the problem is:
<a href=http://www.webdeveloper.com/forum/archive/index.php/"<%= request.getContextPath() %>/jsp/this.jsp?start=<%= (startRow > 99) ? startRow - 100 : 0 %>"
onclick="javascript:<% i = i - startRow; %> return true;">
Back</a>
<a href="<%= request.getContextPath() %>/jsp/this.jsp?start=<%= mybean.getCurrentRow() %>">
Next</a>
The problem is a NullPointerException with setStartRow, but if I take out the onclick code, it almost works; it just doesn't decrement the i counter when I go back.
How do you make this work so the i counter gets decremented when you hit the back button?
Thx