Map model = new HashMap();
String productId = request.getParameter("productId");
if (productId != null) {
PagedListHolder itemList = new PagedListHolder(this.petStore.getItemListByProduct(productId));
itemList.setPageSize(4);
Product product = this.petStore.getProduct(productId);
request.getSession().setAttribute("ViewProductAction_itemList", itemList);
request.getSession().setAttribute("ViewProductAction_product", product);
model.put("itemList", itemList);
model.put("product", product);
}
else {
PagedListHolder itemList = (PagedListHolder) request.getSession().getAttribute("ViewProductAction_itemList");
Product product = (Product) request.getSession().getAttribute("ViewProductAction_product");
String page = request.getParameter("page");
if ("next".equals(page)) {
itemList.nextPage();
}
else if ("previous".equals(page)) {
itemList.previousPage();
}
model.put("itemList", itemList);
model.put("product", product);
}
return new ModelAndView("Product", model);