1 package org.springframework.samples.jpetstore.web.struts; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.http.HttpServletResponse ; 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.Account; 12 13 public class NewAccountAction extends BaseAction { 14 15 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 16 AccountActionForm acctForm = (AccountActionForm) form; 17 if (AccountActionForm.VALIDATE_NEW_ACCOUNT.equals(acctForm.getValidate())) { 18 acctForm.getAccount().setListOption(request.getParameter("account.listOption") != null); 19 acctForm.getAccount().setBannerOption(request.getParameter("account.bannerOption") != null); 20 Account account = acctForm.getAccount(); 21 String username = acctForm.getAccount().getUsername(); 22 getPetStore().insertAccount(account); 23 acctForm.setAccount(getPetStore().getAccount(username)); 24 PagedListHolder myList = new PagedListHolder(getPetStore().getProductListByCategory(account.getFavouriteCategoryId())); 25 myList.setPageSize(4); 26 acctForm.setMyList(myList); 27 request.getSession().setAttribute("accountForm", acctForm); 28 request.getSession().removeAttribute("workingAccountForm"); 29 return mapping.findForward("success"); 30 } 31 else { 32 request.setAttribute("message", "Your account was not created because the submitted information was not validated."); 33 return mapping.findForward("failure"); 34 } 35 } 36 37 } 38 | Popular Tags |