KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > jpetstore > web > struts > ViewProductAction


1 package org.springframework.samples.jpetstore.web.struts;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import javax.servlet.http.HttpServletResponse JavaDoc;
5
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionForward;
8 import org.apache.struts.action.ActionMapping;
9
10 import org.springframework.beans.support.PagedListHolder;
11 import org.springframework.samples.jpetstore.domain.Product;
12
13 public class ViewProductAction extends BaseAction {
14
15   public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
16     String JavaDoc productId = request.getParameter("productId");
17     if (productId != null) {
18             PagedListHolder itemList = new PagedListHolder(getPetStore().getItemListByProduct(productId));
19             itemList.setPageSize(4);
20             Product product = getPetStore().getProduct(productId);
21       request.getSession().setAttribute("ViewProductAction_itemList", itemList);
22             request.getSession().setAttribute("ViewProductAction_product", product);
23             request.setAttribute("itemList", itemList);
24       request.setAttribute("product", product);
25     }
26         else {
27             PagedListHolder itemList = (PagedListHolder) request.getSession().getAttribute("ViewProductAction_itemList");
28             Product product = (Product) request.getSession().getAttribute("ViewProductAction_product");
29       String JavaDoc page = request.getParameter("page");
30       if ("next".equals(page)) {
31         itemList.nextPage();
32       }
33             else if ("previous".equals(page)) {
34         itemList.previousPage();
35       }
36             request.setAttribute("itemList", itemList);
37       request.setAttribute("product", product);
38     }
39     return mapping.findForward("success");
40   }
41
42 }
43
Popular Tags