1 27 package olstore.action; 28 29 import olstore.session.helper.UserHelperLocal; 30 import olstore.session.helper.UserHelperLocalHome; 31 32 import olstore.dto.UserValue; 33 import olstore.form.*; 34 import olstore.framework.EJBHomeFactory; 35 36 import org.apache.commons.beanutils.BeanUtils; 37 38 import javax.servlet.http.*; 40 import org.apache.struts.action.*; 42 43 44 public class UserModAction extends DemoBaseAction { 45 46 50 public ActionForward execute ( ActionMapping mapping, 51 ActionForm form, 52 HttpServletRequest request, 53 HttpServletResponse response) throws Exception{ 54 55 try { 56 DemoDynaBaseForm modUserForm=(DemoDynaBaseForm) form; 57 String action = (String) modUserForm.get("submitType"); 58 59 if ( action.equals("new") ){ 60 loadUser (mapping, form, request, response); 61 return mapping.findForward ("ModUser"); 62 } 63 else if (action.equals("Cancel")){ 64 return new ActionForward("/views/index.do", true); 65 } 66 else { 67 loadUser (mapping, form, request, response); 68 return mapping.findForward ("UpdateUser"); 69 } 70 71 72 } 73 catch ( Exception e ) { 74 ActionErrors errors = new ActionErrors(); 76 errors.add("error", new ActionError("errors.item.load", e.getMessage() )); 77 saveErrors(request, errors); 78 return (new ActionForward(mapping.getInput())); 80 } 81 82 } 83 84 87 public void loadUser (ActionMapping mapping, 88 ActionForm form, 89 HttpServletRequest request, 90 HttpServletResponse response) throws Exception { 91 DemoDynaBaseForm modUserForm=(DemoDynaBaseForm) form; 92 String username=request.getRemoteUser (); 93 EJBHomeFactory factory= EJBHomeFactory.getInstance(); 94 UserHelperLocalHome userHelperHome=(UserHelperLocalHome) factory.getLocalHome (EJBHomeFactory.USER_HELPER); 95 UserHelperLocal userHelper=userHelperHome.create(); 96 UserValue userValue=userHelper.getUserValue (username); 97 98 BeanUtils.copyProperties (modUserForm, userValue); 100 BeanUtils.copyProperties (modUserForm, userValue.getAddress()); 101 } 102 103 } 104 105 106 107 | Popular Tags |