FileDocCategorySizeDatePackage
SearchProductsAction.javaAPI DocExample1675Thu Dec 04 08:19:26 GMT 2003org.springframework.samples.jpetstore.web.struts

SearchProductsAction

public class SearchProductsAction extends BaseAction

Fields Summary
Constructors Summary
Methods Summary
public org.apache.struts.action.ActionForwardexecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

		if (request.getParameter("search") != null) {
			String keyword = request.getParameter("keyword");
			if (keyword == null || keyword.length() == 0) {
				request.setAttribute("message", "Please enter a keyword to search for, then press the search button.");
				return mapping.findForward("failure");
			}
			else {
				PagedListHolder productList = new PagedListHolder(getPetStore().searchProductList(keyword.toLowerCase()));
				productList.setPageSize(4);
				request.getSession().setAttribute("SearchProductsAction_productList", productList);
				request.setAttribute("productList", productList);
				return mapping.findForward("success");
			}
		}
		else {
      String page = request.getParameter("page");
      PagedListHolder productList = (PagedListHolder) request.getSession().getAttribute("SearchProductsAction_productList");
			if ("next".equals(page)) {
				productList.nextPage();
			}
			else if ("previous".equals(page)) {
				productList.previousPage();
			}
			request.setAttribute("productList", productList);
			return mapping.findForward("success");
    }