1 27 package olstore.action; 28 29 30 import javax.ejb.TransactionRolledbackLocalException; 31 import javax.servlet.http.HttpServletRequest; 32 import javax.servlet.http.HttpServletResponse; 33 34 import olstore.dto.AddressValue; 35 import olstore.dto.CreateUserValue; 36 import olstore.form.DemoDynaBaseForm; 37 import olstore.framework.EJBHomeFactory; 38 39 import org.apache.commons.beanutils.BeanUtils; 40 import org.apache.struts.action.ActionError; 41 import org.apache.struts.action.ActionErrors; 42 import org.apache.struts.action.ActionForm; 43 import org.apache.struts.action.ActionForward; 44 import org.apache.struts.action.ActionMapping; 45 46 import olstore.session.helper.UserHelperLocal; 47 import olstore.session.helper.UserHelperLocalHome; 48 49 50 public class UserSaveAction extends DemoBaseAction { 51 52 55 public ActionForward execute ( ActionMapping mapping, 56 ActionForm form, 57 HttpServletRequest request, 58 HttpServletResponse response 59 ) throws Exception { 60 61 try { 62 63 DemoDynaBaseForm createUserForm=(DemoDynaBaseForm) form; 65 CreateUserValue createUserValue=new CreateUserValue (); 66 AddressValue addressValue=new AddressValue(); 67 68 BeanUtils.copyProperties (addressValue, createUserForm); 70 BeanUtils.copyProperties (createUserValue, createUserForm); 71 72 EJBHomeFactory factory=EJBHomeFactory.getInstance (); 73 UserHelperLocalHome userHelperHome=(UserHelperLocalHome) factory.getLocalHome (EJBHomeFactory.USER_HELPER); 74 UserHelperLocal userHelper=userHelperHome.create(); 75 76 userHelper.CreateUser (createUserValue, addressValue); 78 79 return mapping.findForward ("CreateConfirm"); 81 82 } 83 84 catch ( TransactionRolledbackLocalException n){ 86 ActionErrors errors = new ActionErrors(); 87 errors.add ("error", new ActionError("errors.duplicate.username", n.getMessage() )); 88 saveErrors(request,errors); 89 return (new ActionForward(mapping.getInput())); 90 } 91 92 catch ( Exception e ) { 93 ActionErrors errors = new ActionErrors(); 95 errors.add("error", new ActionError("errors.type.save", e.getMessage() )); 96 saveErrors(request, errors); 97 return (new ActionForward(mapping.getInput())); 99 } 100 101 } 102 103 } 104 | Popular Tags |