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 java.util.ArrayList;
29: //import java.util.Collection;
30: //import java.util.Iterator;
31: //import java.util.Vector;
32:
33: import javax.servlet.http.*; //import javax.naming.Context;
34: //import javax.naming.InitialContext;
35:
36: //import olstore.dto.PropertyValue;
37: //import olstore.dto.PictureValue;
38: import olstore.session.helper.TypeHelperLocal;
39: import olstore.session.helper.TypeHelperLocalHome; //import olstore.entity.TypeLocal;
40: //import olstore.entity.TypeLocalHome;
41: //import olstore.entity.PropertyLocal;
42:
43: import olstore.dto.TypeValue;
44: import olstore.form.CreateTypeForm;
45: import olstore.framework.EJBHomeFactory;
46:
47: import org.apache.struts.action.*;
48: import org.apache.commons.beanutils.BeanUtils;
49:
50: public class TypeSaveAction extends DemoBaseAction {
51:
52: public ActionForward execute(ActionMapping mapping,
53: ActionForm form, HttpServletRequest request,
54: HttpServletResponse response) throws Exception {
55:
56: try {
57:
58: CreateTypeForm createForm = (CreateTypeForm) form;
59: TypeValue typeVal = new TypeValue();
60: BeanUtils.copyProperties(typeVal, createForm);
61:
62: EJBHomeFactory factory = EJBHomeFactory.getInstance();
63: TypeHelperLocalHome typeHelperHome = (TypeHelperLocalHome) factory
64: .getLocalHome(EJBHomeFactory.TYPE_HELPER);
65: TypeHelperLocal typeHelper = typeHelperHome.create();
66:
67: typeHelper.saveType(typeVal);
68:
69: ActionMessages messages = new ActionMessages();
70: ActionMessage msg = new ActionMessage("type.save.success",
71: typeVal.getName());
72: messages.add("success", msg);
73: saveMessages(request, messages);
74:
75: return mapping.findForward("updateType");
76: } catch (Exception e) {
77: //Logging code here
78: ActionErrors errors = new ActionErrors();
79: errors.add("error", new ActionError("errors.type.save", e
80: .getMessage()));
81: saveErrors(request, errors);
82: // Return to same page
83: return (new ActionForward(mapping.getInput()));
84: }
85:
86: }
87:
88: }
|