KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > olstore > action > UserCreateAction


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 javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 import olstore.form.DemoDynaBaseForm;
33
34 import org.apache.struts.action.ActionError;
35 import org.apache.struts.action.ActionErrors;
36 import org.apache.struts.action.ActionForm;
37 import org.apache.struts.action.ActionForward;
38 import org.apache.struts.action.ActionMapping;
39
40
41
42 public class UserCreateAction extends DemoBaseAction {
43     
44     /**
45      * Acts as a relay for all user creation related tasks
46      *
47      */

48     
49     public ActionForward execute ( ActionMapping mapping,
50             ActionForm form,
51             HttpServletRequest request,
52             HttpServletResponse response) throws Exception{
53         
54         try {
55             DemoDynaBaseForm createUserForm=(DemoDynaBaseForm) form;
56             String action = (String) createUserForm.get("submitType");
57             if ( action.equals("new") ){
58                 return mapping.findForward ("CreateUser");
59             }
60             else if (action.equals("Cancel")){
61                 return new ActionForward("/views/index.do", true);
62             }
63             else {
64                 return mapping.findForward ("SaveUser");
65             }
66             
67         }
68         catch ( Exception e ) {
69             //Logging code here
70
ActionErrors errors = new ActionErrors();
71             errors.add("error", new ActionError("errors.item.load", e.getMessage() ));
72             saveErrors(request, errors);
73             // Return to same page
74
return (new ActionForward(mapping.getInput()));
75         }
76         
77     }
78 }
79
80
81
82
Popular Tags