KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > olstore > action > UserModAction


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 olstore.session.helper.UserHelperLocal;
30 import olstore.session.helper.UserHelperLocalHome;
31
32 import olstore.dto.UserValue;
33 import olstore.form.*;
34 import olstore.framework.EJBHomeFactory;
35
36 import org.apache.commons.beanutils.BeanUtils;
37
38 //import javax.servlet.*;
39
import javax.servlet.http.*;
40 //import olstore.entity.*;
41
import org.apache.struts.action.*;
42
43
44 public class UserModAction extends DemoBaseAction {
45     
46     /**
47      * Acts as a relay for all user modification related tasks with a default action
48      *
49      */

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

87     public void loadUser (ActionMapping mapping,
88             ActionForm form,
89             HttpServletRequest request,
90             HttpServletResponse response) throws Exception {
91         DemoDynaBaseForm modUserForm=(DemoDynaBaseForm) form;
92         String username=request.getRemoteUser ();
93         EJBHomeFactory factory= EJBHomeFactory.getInstance();
94         UserHelperLocalHome userHelperHome=(UserHelperLocalHome) factory.getLocalHome (EJBHomeFactory.USER_HELPER);
95         UserHelperLocal userHelper=userHelperHome.create();
96         UserValue userValue=userHelper.getUserValue (username);
97         
98         //copy values from the DTO to the form
99
BeanUtils.copyProperties (modUserForm, userValue);
100         BeanUtils.copyProperties (modUserForm, userValue.getAddress());
101     }
102     
103 }
104
105
106
107
Popular Tags