1 18 19 package org.apache.struts.webapp.example; 20 21 import java.lang.reflect.InvocationTargetException ; 22 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.http.HttpSession ; 27 28 import org.apache.commons.beanutils.PropertyUtils; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 import org.apache.struts.action.Action; 32 import org.apache.struts.action.ActionForm; 33 import org.apache.struts.action.ActionForward; 34 import org.apache.struts.action.ActionMapping; 35 36 43 public final class EditRegistrationAction extends Action { 44 45 47 50 private Log log = LogFactory.getLog("org.apache.struts.webapp.Example"); 51 52 54 public ActionForward execute( 56 ActionMapping mapping, 57 ActionForm form, 58 HttpServletRequest request, 59 HttpServletResponse response) 60 throws Exception { 61 62 HttpSession session = request.getSession(); 64 String action = request.getParameter("action"); 65 if (action == null) { 66 action = "Create"; 67 } 68 69 if (log.isDebugEnabled()) { 70 log.debug("EditRegistrationAction: Processing " + action + " action"); 71 } 72 73 User user = null; 75 if (!"Create".equals(action)) { 76 user = (User) session.getAttribute(Constants.USER_KEY); 77 if (user == null) { 78 if (log.isDebugEnabled()) { 79 log.debug( 80 " User is not logged on in session " + session.getId()); 81 } 82 return (mapping.findForward("logon")); 83 } 84 } 85 86 RegistrationForm regform = (RegistrationForm) form; 87 if (user != null) { 88 if (log.isTraceEnabled()) { 89 log.trace(" Populating form from " + user); 90 } 91 92 try { 93 PropertyUtils.copyProperties(regform, user); 94 regform.setAction(action); 95 regform.setPassword(null); 96 regform.setPassword2(null); 97 98 } catch (InvocationTargetException e) { 99 Throwable t = e.getTargetException(); 100 if (t == null) 101 t = e; 102 log.error("RegistrationForm.populate", t); 103 throw new ServletException ("RegistrationForm.populate", t); 104 105 } catch (Throwable t) { 106 log.error("RegistrationForm.populate", t); 107 throw new ServletException ("RegistrationForm.populate", t); 108 } 109 } 110 111 if (log.isTraceEnabled()) { 113 log.trace(" Setting transactional control token"); 114 } 115 116 saveToken(request); 117 118 if (log.isTraceEnabled()) { 120 log.trace(" Forwarding to 'success' page"); 121 } 122 123 return (mapping.findForward("success")); 124 125 } 126 127 } 128 | Popular Tags |