KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > olstore > action > TypeSaveAction


1 /**
2  * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * 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  */

27 package olstore.action;
28
29 //import java.util.ArrayList;
30
//import java.util.Collection;
31
//import java.util.Iterator;
32
//import java.util.Vector;
33

34 import javax.servlet.http.*;
35 //import javax.naming.Context;
36
//import javax.naming.InitialContext;
37

38 //import olstore.dto.PropertyValue;
39
//import olstore.dto.PictureValue;
40
import olstore.session.helper.TypeHelperLocal;
41 import olstore.session.helper.TypeHelperLocalHome;
42 //import olstore.entity.TypeLocal;
43
//import olstore.entity.TypeLocalHome;
44
//import olstore.entity.PropertyLocal;
45

46 import olstore.dto.TypeValue;
47 import olstore.form.CreateTypeForm;
48 import olstore.framework.EJBHomeFactory;
49
50 import org.apache.struts.action.*;
51 import org.apache.commons.beanutils.BeanUtils;
52
53
54 public class TypeSaveAction extends DemoBaseAction {
55     
56     public ActionForward execute ( ActionMapping mapping,
57             ActionForm form,
58             HttpServletRequest request,
59             HttpServletResponse response
60     ) throws Exception {
61         
62         try {
63             
64             CreateTypeForm createForm = (CreateTypeForm)form;
65             TypeValue typeVal = new TypeValue();
66             BeanUtils.copyProperties ( typeVal , createForm );
67             
68             EJBHomeFactory factory = EJBHomeFactory.getInstance();
69             TypeHelperLocalHome typeHelperHome = (TypeHelperLocalHome) factory.getLocalHome ( EJBHomeFactory.TYPE_HELPER );
70             TypeHelperLocal typeHelper = typeHelperHome.create();
71             
72             typeHelper.saveType ( typeVal );
73             
74             ActionMessages messages = new ActionMessages();
75             ActionMessage msg = new ActionMessage("type.save.success",
76                     typeVal.getName() );
77             messages.add("success", msg);
78             saveMessages(request, messages);
79             
80             return mapping.findForward ( "updateType" );
81         } catch ( Exception e ) {
82             //Logging code here
83
ActionErrors errors = new ActionErrors();
84             errors.add("error", new ActionError("errors.type.save", e.getMessage() ));
85             saveErrors(request, errors);
86             // Return to same page
87
return (new ActionForward(mapping.getInput()));
88         }
89         
90     }
91     
92 }
93
Popular Tags