You've got a lot of issues here...I've implemented similar front-end functionality, a screen displaying paged search results that the user can navigate through by page. But did it in a somewhat simpler way.
I'd strongly suggest using setFirstResult/setMaxResults rather than messing with scrollable result sets. You may wind up hitting the database a bit more, but the code is simpler. This way, the only user state you need to maintain between requests is the page size and the offset. When the user requests another page, you just create a new query and pull a fresh set of objects. Of course, this is probably not the best pattern for a high-concurrency enviro.
In my own app, I've got a DTO that holds all the user's search criteria, along with the page size and offset. After the user submits a DynaActionForm, I use beanutils to copy the data to the DTO. I store it in the user's httpsession. Here's the code to handle a user's request for the prev/next page:
Code:
if(request.getParameter("init") != null ){
filterDTO = new FilterDTO(); }
else{
filterDTO = (FilterDTO)mysession.getAttribute("FilterParams");
if(request.getParameter("offset") != null){
String offset = request.getParameter("offset");
if(offset.equalsIgnoreCase("fwd")){
int newoffset = filterDTO.getOffset() + filterDTO.getPagesize();
filterDTO.setOffset(newoffset);
}
if(offset.equalsIgnoreCase("rev")){
int newoffset = filterDTO.getOffset() - filterDTO.getPagesize();
filterDTO.setOffset(newoffset);
}
}
}
Then I send the DTO to my service layer, where Hibernate pulls a new set of objects according to the filter criteria.