Source Code Cross Referenced for EditUserController.java in  » J2EE » JOnAS-4.8.6 » olstore » controller » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » olstore.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2006 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: Greg Lapouchnian
022:         *                     Patrick Smith
023:         *
024:         */package olstore.controller;
025:
026:        import java.util.Map;
027:
028:        import javax.servlet.http.HttpServletRequest;
029:        import javax.servlet.http.HttpServletResponse;
030:
031:        import olstore.domain.logic.OlstoreFacade;
032:        import olstore.dto.AddressValue;
033:        import olstore.dto.UserValue;
034:
035:        import org.springframework.validation.BindException;
036:        import org.springframework.validation.ValidationUtils;
037:        import org.springframework.web.servlet.ModelAndView;
038:        import org.springframework.web.servlet.mvc.SimpleFormController;
039:
040:        /**
041:         * Controller class used for editing a user's profile.
042:         */
043:        public class EditUserController extends SimpleFormController {
044:
045:            // olstore instance injected by Spring.
046:            private OlstoreFacade olstore;
047:
048:            /**
049:             * Creates a new form object with default values set, such as
050:             * what command class to use as the backing object, and which views to use.
051:             */
052:            public EditUserController() {
053:                setSessionForm(true);
054:                setValidateOnBinding(false);
055:                setCommandClass(UserForm.class);
056:                setFormView("editUser");
057:                setSuccessView("editUser");
058:            }
059:
060:            /**
061:             * Spring injection method for setting the olstore bean instance.
062:             * @param olstore the instance of olstore injected via spring.
063:             */
064:            public void setOlstore(OlstoreFacade olstore) {
065:                this .olstore = olstore;
066:            }
067:
068:            /**
069:             * Returns the backing object that this form will use.
070:             * 
071:             * @param request the HttpServletRequest
072:             * @return this form's backing object.
073:             */
074:            protected Object formBackingObject(HttpServletRequest request)
075:                    throws Exception {
076:                String user = request.getRemoteUser();
077:
078:                // Supply the form backing object UserForm with the User and Address DTOs
079:                UserValue userValue = olstore.getUser(user);
080:                AddressValue addressValue = new AddressValue();
081:                addressValue.setStreet1(userValue.getAddress().getStreet1());
082:                addressValue.setStreet2(userValue.getAddress().getStreet2());
083:                addressValue.setCity(userValue.getAddress().getCity());
084:                addressValue.setProvince(userValue.getAddress().getProvince());
085:                addressValue.setPostalCode(userValue.getAddress()
086:                        .getPostalCode());
087:                addressValue.setCountry(userValue.getAddress().getCountry());
088:
089:                return new UserForm(userValue, addressValue);
090:            }
091:
092:            /**
093:             * Validation method to handle the command's fields.
094:             * 
095:             * @param request the HttpServletRequest.
096:             * @param command the backing object for this form.
097:             * @param errors the errors to report when validation fails.
098:             */
099:            protected void onBindAndValidate(HttpServletRequest request,
100:                    Object command, BindException errors) throws Exception {
101:                ValidationUtils.rejectIfEmptyOrWhitespace(errors, "user.fname",
102:                        "FNAME_REQUIRED", "First name is required.");
103:                ValidationUtils.rejectIfEmptyOrWhitespace(errors, "user.lname",
104:                        "LNAME_REQUIRED", "Last name is required.");
105:                // TODO 
106:            }
107:
108:            /**
109:             * Returns the map model to use for this form's view.
110:             * 
111:             * @param request the HttpServletRequest.
112:             * @return a model to be used on this form's view.
113:             */
114:            protected Map referenceData(HttpServletRequest request)
115:                    throws Exception {
116:                Map model = ControllerHelper.initModel(request, olstore);
117:                model.put("page_title", "Edit Your Information - Olstore");
118:                model.put("allUsers", this .olstore.getAllUsers());
119:                return model;
120:            }
121:
122:            /**
123:             * Handles the submission of this form.
124:             * 
125:             * @param request the HttpServletRequest.
126:             * @param response the HttpServletResponse.
127:             * @param command this forms backing object.
128:             * @param errors this form's errors as reported via validation.
129:             * @return a new model and view to represent this form.
130:             */
131:            protected ModelAndView onSubmit(HttpServletRequest request,
132:                    HttpServletResponse response, Object command,
133:                    BindException errors) throws Exception {
134:                // supply the errors to the view inside the model map
135:                Map model = errors.getModel();
136:                // add the reference data once again so it will continue to be displayed
137:                model.putAll(referenceData(request));
138:
139:                UserForm userForm = (UserForm) command;
140:                try {
141:                    if (userForm.getUser().getFriendsListSelected() == null) {
142:                        userForm.getUser().setFriendsListSelected(
143:                                new String[] {});
144:                    }
145:
146:                    this .olstore.saveUser(userForm.getUser(), userForm
147:                            .getAddress(), userForm.getUser().getUsername());
148:                } catch (Exception ex) {
149:                    model
150:                            .put("error",
151:                                    "There was an error trying to save your account information.");
152:                    return showForm(request, response, errors, model);
153:                }
154:
155:                model.put("message",
156:                        "Your information has been successfully updated.");
157:                model.put("command", formBackingObject(request));
158:                return new ModelAndView("editUser", model);
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.