Source Code Cross Referenced for CreateTypeController.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.ArrayList;
027:        import java.util.Iterator;
028:        import java.util.Map;
029:
030:        import javax.servlet.http.HttpServletRequest;
031:        import javax.servlet.http.HttpServletResponse;
032:
033:        import olstore.domain.logic.OlstoreFacade;
034:        import olstore.dto.PropertyValue;
035:        import olstore.dto.TypeValue;
036:
037:        import org.springframework.validation.BindException;
038:        import org.springframework.validation.ValidationUtils;
039:        import org.springframework.web.servlet.ModelAndView;
040:        import org.springframework.web.servlet.mvc.SimpleFormController;
041:
042:        /**
043:         * A simple form controller to handle creating a new type.
044:         */
045:        public class CreateTypeController extends SimpleFormController {
046:
047:            // Olstore instance injected by Spring.
048:            private OlstoreFacade olstore;
049:
050:            /**
051:             * Creates a new controller and sets the class to use as a backing object
052:             * as well as views, and validation.
053:             *
054:             */
055:            public CreateTypeController() {
056:                setSessionForm(true);
057:                setValidateOnBinding(false);
058:                setCommandClass(TypeValue.class);
059:                setFormView("createType");
060:                setSuccessView("createType");
061:            }
062:
063:            /**
064:             * Spring method for dependency injection.
065:             * @param olstore supplied via spring.
066:             */
067:            public void setOlstore(OlstoreFacade olstore) {
068:                this .olstore = olstore;
069:            }
070:
071:            /**
072:             * Returns the object that will be used as the form's backing object.
073:             * 
074:             * @param request the HttpServletRequest object.
075:             * @return the object that this form will use as its backing object.
076:             */
077:            protected Object formBackingObject(HttpServletRequest request)
078:                    throws Exception {
079:                TypeValue type = new TypeValue();
080:                ArrayList props = new ArrayList();
081:                props.add(new PropertyValue());
082:                type.setProperties(props);
083:                return type;
084:            }
085:
086:            /**
087:             * Sets what validation is to be done on the command object's fields.
088:             * 
089:             * @param request the HttpServletRequest
090:             * @param command the command object used as the backing object.
091:             * @param errors where the errors are reported if validation fails.
092:             */
093:            protected void onBindAndValidate(HttpServletRequest request,
094:                    Object command, BindException errors) throws Exception {
095:
096:                System.out.println("need to validate");
097:                if (!isFormChangeRequest(request)) {
098:                    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name",
099:                            "NAME_REQUIRED", "Type name is required.");
100:                    TypeValue type = (TypeValue) command;
101:                    Iterator i = type.getProperties().iterator();
102:                    while (i.hasNext()) {
103:                        PropertyValue prop = (PropertyValue) i.next();
104:                        if (prop.getName() == null
105:                                || prop.getName().length() == 0) {
106:                            errors.rejectValue("properties", "PROP_REQUIRED",
107:                                    "Property name is required.");
108:                        }
109:                    }
110:                }
111:            }
112:
113:            /**
114:             * The initial model to be used in this form.
115:             * 
116:             * @param request the HttpServletRequest object.
117:             * @return a map that represents the model to be used in the view.
118:             */
119:            protected Map referenceData(HttpServletRequest request)
120:                    throws Exception {
121:                Map model = ControllerHelper.initModel(request, olstore);
122:                model.put("page_title", "Create New Type - Olstore");
123:                model.put("types", this .olstore.getTypes());
124:                return model;
125:            }
126:
127:            /**
128:             * Handles the submission of the simple form object, and returns a new
129:             * model and view to represent the changes.
130:             * 
131:             * @param request the HttpServletRequest
132:             * @param response the HttpServletResponse
133:             * @param command the backing object of this form.
134:             * @param errors the errors to report for this form's validation.
135:             * @return a new model and view to represent the form.
136:             */
137:            protected ModelAndView onSubmit(HttpServletRequest request,
138:                    HttpServletResponse response, Object command,
139:                    BindException errors) throws Exception {
140:                // supply the errors to the view inside the model map
141:                Map model = errors.getModel();
142:                // add the reference data once again so it will continue to be displayed
143:                model.putAll(referenceData(request));
144:
145:                TypeValue type = (TypeValue) command;
146:                try {
147:                    this .olstore.saveType(type);
148:                } catch (Exception ex) {
149:                    model.put("error",
150:                            "There was an error trying to save your new type.");
151:                    return showForm(request, response, errors, model);
152:                }
153:                // refresh the types displayed on the sidebar to include the newly added one
154:                model.put("types", this .olstore.getTypes());
155:
156:                model.put("message", "New type successfully saved.");
157:                return new ModelAndView("createType", model);
158:            }
159:
160:            /**
161:             * Called when the form is changed so that if a new property is needed
162:             * it can be properly added to the backing command object.
163:             * 
164:             * @param request the HttpServletRequest.
165:             * @param response the HttpServletResponse
166:             * @param command the backing objecdt of this form.
167:             */
168:            protected void onFormChange(HttpServletRequest request,
169:                    HttpServletResponse response, Object command)
170:                    throws Exception {
171:                TypeValue type = (TypeValue) command;
172:                // add another property to the object
173:                type.getProperties().add(new PropertyValue());
174:            }
175:
176:            /**
177:             * Checks to see if the request is to change the form, or an actual submit.
178:             * 
179:             * @param request the HttpServletRequest
180:             * @return true if the request is to change the form, false otherwise.
181:             */
182:            protected boolean isFormChangeRequest(HttpServletRequest request) {
183:                return request.getParameter("add-property") != null;
184:            }
185:
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.