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.HttpServletRequest;
29: import javax.servlet.http.HttpServletResponse;
30:
31: import olstore.form.DemoDynaBaseForm;
32:
33: import org.apache.struts.action.ActionError;
34: import org.apache.struts.action.ActionErrors;
35: import org.apache.struts.action.ActionForm;
36: import org.apache.struts.action.ActionForward;
37: import org.apache.struts.action.ActionMapping;
38:
39: public class UserCreateAction extends DemoBaseAction {
40:
41: /**
42: * Acts as a relay for all user creation related tasks
43: *
44: */
45:
46: public ActionForward execute(ActionMapping mapping,
47: ActionForm form, HttpServletRequest request,
48: HttpServletResponse response) throws Exception {
49:
50: try {
51: DemoDynaBaseForm createUserForm = (DemoDynaBaseForm) form;
52: String action = (String) createUserForm.get("submitType");
53: if (action.equals("new")) {
54: return mapping.findForward("CreateUser");
55: } else if (action.equals("Cancel")) {
56: return new ActionForward("/views/index.do", true);
57: } else {
58: return mapping.findForward("SaveUser");
59: }
60:
61: } catch (Exception e) {
62: //Logging code here
63: ActionErrors errors = new ActionErrors();
64: errors.add("error", new ActionError("errors.item.load", e
65: .getMessage()));
66: saveErrors(request, errors);
67: // Return to same page
68: return (new ActionForward(mapping.getInput()));
69: }
70:
71: }
72: }
|