Source Code Cross Referenced for ServletRequestDataBinder.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » bind » 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 » spring framework 2.0.6 » org.springframework.web.bind 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.web.bind;
018:
019:        import javax.servlet.ServletRequest;
020:
021:        import org.springframework.beans.MutablePropertyValues;
022:        import org.springframework.validation.BindException;
023:        import org.springframework.web.multipart.MultipartHttpServletRequest;
024:
025:        /**
026:         * Special DataBinder to perform data binding from servlet request parameters
027:         * to JavaBeans, including support for multipart files.
028:         *
029:         * <p>See the DataBinder/WebDataBinder superclasses for customization options,
030:         * which include specifying allowed/required fields, and registering custom
031:         * property editors.
032:         *
033:         * <p>Used by Spring web MVC's BaseCommandController and MultiActionController.
034:         * Note that BaseCommandController and its subclasses allow for easy customization
035:         * of the binder instances that they use through overriding <code>initBinder</code>.
036:         *
037:         * <p>Can also be used for manual data binding in custom web controllers:
038:         * for example, in a plain Controller implementation or in a MultiActionController
039:         * handler method. Simply instantiate a ServletRequestDataBinder for each binding
040:         * process, and invoke <code>bind</code> with the current ServletRequest as argument:
041:         *
042:         * <pre>
043:         * MyBean myBean = new MyBean();
044:         * // apply binder to custom target object
045:         * ServletRequestDataBinder binder = new ServletRequestDataBinder(myBean);
046:         * // register custom editors, if desired
047:         * binder.registerCustomEditor(...);
048:         * // trigger actual binding of request parameters
049:         * binder.bind(request);
050:         * // optionally evaluate binding errors
051:         * Errors errors = binder.getErrors();
052:         * ...</pre>
053:         *
054:         * @author Rod Johnson
055:         * @author Juergen Hoeller
056:         * @see #bind(javax.servlet.ServletRequest)
057:         * @see #registerCustomEditor
058:         * @see #setAllowedFields
059:         * @see #setRequiredFields
060:         * @see #setFieldMarkerPrefix
061:         * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
062:         */
063:        public class ServletRequestDataBinder extends WebDataBinder {
064:
065:            /**
066:             * Create a new ServletRequestDataBinder instance, with default object name.
067:             * @param target target object to bind onto
068:             * @see #DEFAULT_OBJECT_NAME
069:             */
070:            public ServletRequestDataBinder(Object target) {
071:                super (target);
072:            }
073:
074:            /**
075:             * Create a new ServletRequestDataBinder instance.
076:             * @param target target object to bind onto
077:             * @param objectName objectName of the target object
078:             */
079:            public ServletRequestDataBinder(Object target, String objectName) {
080:                super (target, objectName);
081:            }
082:
083:            /**
084:             * Bind the parameters of the given request to this binder's target,
085:             * also binding multipart files in case of a multipart request.
086:             * <p>This call can create field errors, representing basic binding
087:             * errors like a required field (code "required"), or type mismatch
088:             * between value and bean property (code "typeMismatch").
089:             * <p>Multipart files are bound via their parameter name, just like normal
090:             * HTTP parameters: i.e. "uploadedFile" to an "uploadedFile" bean property,
091:             * invoking a "setUploadedFile" setter method.
092:             * <p>The type of the target property for a multipart file can be MultipartFile,
093:             * byte[], or String. The latter two receive the contents of the uploaded file;
094:             * all metadata like original file name, content type, etc are lost in those cases.
095:             * @param request request with parameters to bind (can be multipart)
096:             * @see org.springframework.web.multipart.MultipartHttpServletRequest
097:             * @see org.springframework.web.multipart.MultipartFile
098:             * @see #bindMultipartFiles
099:             * @see #bind(org.springframework.beans.PropertyValues)
100:             */
101:            public void bind(ServletRequest request) {
102:                MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(
103:                        request);
104:                if (request instanceof  MultipartHttpServletRequest) {
105:                    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
106:                    bindMultipartFiles(multipartRequest.getFileMap(), mpvs);
107:                }
108:                doBind(mpvs);
109:            }
110:
111:            /**
112:             * Treats errors as fatal. Use this method only if
113:             * it's an error if the input isn't valid.
114:             * This might be appropriate if all input is from dropdowns, for example.
115:             * @throws ServletRequestBindingException subclass of ServletException on any binding problem
116:             */
117:            public void closeNoCatch() throws ServletRequestBindingException {
118:                if (getBindingResult().hasErrors()) {
119:                    throw new ServletRequestBindingException(
120:                            "Errors binding onto object '"
121:                                    + getBindingResult().getObjectName() + "'",
122:                            new BindException(getBindingResult()));
123:                }
124:            }
125:
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.