001: /**
002: * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017: * USA
018: *
019: * Component of: Red Hat Application Server
020: *
021: * Initial Developers: Aizaz Ahmed
022: * Vivek Lakshmanan
023: * Andrew Overholt
024: * Matthew Wringe
025: *
026: */package olstore.action;
027:
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030:
031: import olstore.dto.AddressValue;
032: import olstore.dto.UserValue;
033: import olstore.form.DemoDynaBaseForm;
034: import olstore.framework.EJBHomeFactory;
035:
036: import org.apache.commons.beanutils.BeanUtils;
037: import org.apache.struts.action.ActionError;
038: import org.apache.struts.action.ActionErrors;
039: import org.apache.struts.action.ActionForm;
040: import org.apache.struts.action.ActionForward;
041: import org.apache.struts.action.ActionMapping;
042: import org.apache.struts.action.ActionMessage;
043: import org.apache.struts.action.ActionMessages;
044:
045: import olstore.session.helper.UserHelperLocal;
046: import olstore.session.helper.UserHelperLocalHome;
047:
048: public class UserUpdateAction extends DemoBaseAction {
049:
050: /**
051: * Action to update a users profile.
052: */
053: public ActionForward execute(ActionMapping mapping,
054: ActionForm form, HttpServletRequest request,
055: HttpServletResponse response) throws Exception {
056:
057: try {
058:
059: DemoDynaBaseForm modUserForm = (DemoDynaBaseForm) form;
060: UserValue userValue = new UserValue();
061: AddressValue addressValue = new AddressValue();
062:
063: //copy properties from the form to the DTOs
064: BeanUtils.copyProperties(addressValue, modUserForm);
065: BeanUtils.copyProperties(userValue, modUserForm);
066:
067: String username = request.getRemoteUser();
068: EJBHomeFactory factory = EJBHomeFactory.getInstance();
069: UserHelperLocalHome userHelperHome = (UserHelperLocalHome) factory
070: .getLocalHome(EJBHomeFactory.USER_HELPER);
071: UserHelperLocal userHelper = userHelperHome.create();
072:
073: //save the information to the entity beans
074: userHelper.SaveUser(userValue, addressValue, username);
075:
076: //to load the page the next time
077: modUserForm.set("submitType", "new");
078:
079: //reload the saved info back into the form.
080: UserModAction modAction = new UserModAction();
081: modAction.loadUser(mapping, form, request, response);
082:
083: //create a message that the user's info was updated
084: ActionMessages messages = new ActionMessages();
085: ActionMessage msg = new ActionMessage("user.save.success",
086: username);
087: messages.add("success", msg);
088: saveMessages(request, messages);
089:
090: //return back to the same page
091: return (new ActionForward(mapping.getInput()));
092:
093: } catch (Exception e) {
094: //Logging code here
095: ActionErrors errors = new ActionErrors();
096: errors.add("error", new ActionError("errors.type.save", e
097: .getMessage()));
098: saveErrors(request, errors);
099: // Return to same page
100: return (new ActionForward(mapping.getInput()));
101: }
102:
103: }
104: }
|