1 18 19 package org.apache.struts.webapp.validator; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 import javax.servlet.http.HttpSession ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.struts.action.Action; 28 import org.apache.struts.action.ActionForm; 29 import org.apache.struts.action.ActionForward; 30 import org.apache.struts.action.ActionMapping; 31 import org.apache.struts.action.ActionMessages; 32 33 38 public final class MultiRegistrationAction extends Action { 39 40 43 private Log log = LogFactory.getFactory().getInstance(this.getClass().getName()); 44 45 59 public ActionForward execute( 60 ActionMapping mapping, 61 ActionForm form, 62 HttpServletRequest request, 63 HttpServletResponse response) 64 throws Exception { 65 66 RegistrationForm info = (RegistrationForm) form; 68 69 70 if (isCancelled(request)) { 72 if (log.isInfoEnabled()) { 73 log.info( 74 " " 75 + mapping.getAttribute() 76 + " - Registration transaction was cancelled"); 77 } 78 79 removeFormBean(mapping, request); 80 81 return mapping.findForward("success"); 82 } 83 84 ActionMessages errors = info.validate(mapping, request); 85 86 if (errors != null && errors.isEmpty()) { 87 if (info.getPage() == 1) 88 return mapping.findForward("input2"); 89 90 if (info.getPage() == 2) 91 return mapping.findForward("success"); 92 93 } else { 94 this.saveErrors(request, errors); 95 96 if (info.getPage() == 1){ 97 return mapping.findForward("input" + info.getPage()); 98 } 99 100 if (info.getPage() == 2){ 101 return mapping.findForward("input" + info.getPage()); 102 } 103 } 104 105 return mapping.findForward("input1"); 106 } 107 108 114 protected void removeFormBean( 115 ActionMapping mapping, 116 HttpServletRequest request) { 117 118 if (mapping.getAttribute() != null) { 120 if ("request".equals(mapping.getScope())) { 121 request.removeAttribute(mapping.getAttribute()); 122 } else { 123 HttpSession session = request.getSession(); 124 session.removeAttribute(mapping.getAttribute()); 125 } 126 } 127 } 128 } 129 | Popular Tags |