01: /**
02: * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17: * USA
18: *
19: * Component of: Red Hat Application Server
20: *
21: * Initial Developers: Aizaz Ahmed
22: * Vivek Lakshmanan
23: * Andrew Overholt
24: * Matthew Wringe
25: *
26: */package olstore.action;
27:
28: import javax.servlet.http.*;
29: import olstore.session.helper.ItemHelperLocal;
30: import olstore.session.helper.ItemHelperLocalHome;
31: import olstore.dto.ItemValue;
32: import olstore.form.CreateItemForm;
33: import olstore.framework.EJBHomeFactory;
34:
35: import org.apache.struts.action.*;
36: import org.apache.commons.beanutils.BeanUtils;
37:
38: public class ItemSaveAction extends DemoBaseAction {
39:
40: /**
41: * Acts as a relay for all item related tasks with a default action
42: *
43: */
44: public ActionForward execute(ActionMapping mapping,
45: ActionForm form, HttpServletRequest request,
46: HttpServletResponse response) throws Exception {
47:
48: try {
49:
50: CreateItemForm createForm = (CreateItemForm) form;
51: ItemValue itemVal = new ItemValue();
52: BeanUtils.copyProperties(itemVal, createForm);
53:
54: EJBHomeFactory factory = EJBHomeFactory.getInstance();
55: ItemHelperLocalHome itemHelperHome = (ItemHelperLocalHome) factory
56: .getLocalHome(EJBHomeFactory.ITEM_HELPER);
57: ItemHelperLocal itemHelper = itemHelperHome.create();
58:
59: itemHelper.saveItem(itemVal);
60:
61: ActionMessages messages = new ActionMessages();
62: ActionMessage msg = new ActionMessage("item.save.success",
63: itemVal.getName());
64: messages.add("success", msg);
65: saveMessages(request, messages);
66:
67: return mapping.findForward("updateItem");
68: } catch (Exception e) {
69: //Logging code here
70: e.printStackTrace();
71: ActionErrors errors = new ActionErrors();
72: errors.add("error", new ActionError("errors.item.save", e
73: .getMessage()));
74: saveErrors(request, errors);
75: // Return to same page
76: return (new ActionForward(mapping.getInput()));
77: }
78:
79: }
80:
81: }
|