1 27 package olstore.action; 28 29 import javax.servlet.http.*; 30 import olstore.session.helper.ItemHelperLocal; 31 import olstore.session.helper.ItemHelperLocalHome; 32 import olstore.dto.ItemValue; 33 import olstore.form.CreateItemForm; 34 import olstore.framework.EJBHomeFactory; 35 36 import org.apache.struts.action.*; 37 import org.apache.commons.beanutils.BeanUtils; 38 39 40 public class ItemSaveAction extends DemoBaseAction { 41 42 46 public ActionForward execute ( ActionMapping mapping, 47 ActionForm form, 48 HttpServletRequest request, 49 HttpServletResponse response 50 ) throws Exception { 51 52 try { 53 54 CreateItemForm createForm = (CreateItemForm)form; 55 ItemValue itemVal = new ItemValue(); 56 BeanUtils.copyProperties ( itemVal , createForm ); 57 58 EJBHomeFactory factory = EJBHomeFactory.getInstance(); 59 ItemHelperLocalHome itemHelperHome = (ItemHelperLocalHome) factory.getLocalHome ( EJBHomeFactory.ITEM_HELPER ); 60 ItemHelperLocal itemHelper = itemHelperHome.create(); 61 62 itemHelper.saveItem ( itemVal ); 63 64 ActionMessages messages = new ActionMessages(); 65 ActionMessage msg = new ActionMessage("item.save.success", 66 itemVal.getName() ); 67 messages.add("success", msg); 68 saveMessages(request, messages); 69 70 return mapping.findForward ( "updateItem" ); 71 } catch ( Exception e ) { 72 e.printStackTrace(); 74 ActionErrors errors = new ActionErrors(); 75 errors.add("error", new ActionError("errors.item.save", e.getMessage() )); 76 saveErrors(request, errors); 77 return (new ActionForward(mapping.getInput())); 79 } 80 81 } 82 83 } 84 | Popular Tags |