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 EditAccountAction extends SecureBaseAction { 14 15 protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 16 AccountActionForm acctForm = (AccountActionForm) form; 17 if (AccountActionForm.VALIDATE_EDIT_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 getPetStore().updateAccount(account); 22 acctForm.setAccount(getPetStore().getAccount(account.getUsername())); 23 PagedListHolder myList = new PagedListHolder(getPetStore().getProductListByCategory(account.getFavouriteCategoryId())); 24 myList.setPageSize(4); 25 acctForm.setMyList(myList); 26 request.getSession().setAttribute("accountForm", acctForm); 27 request.getSession().removeAttribute("workingAccountForm"); 28 return mapping.findForward("success"); 29 } 30 else { 31 request.setAttribute("message", "Your account was not updated because the submitted information was not validated."); 32 return mapping.findForward("failure"); 33 } 34 } 35 36 } 37 | Popular Tags |