Java Doc for DataBinder.java in  » J2EE » spring-framework-2.0.6 » org » springframework » validation » 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.validation 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.validation.DataBinder

All known Subclasses:   org.springframework.web.bind.WebDataBinder,
DataBinder
public class DataBinder implements PropertyEditorRegistry(Code)
Binder that allows for setting property values onto a target object, including support for validation and binding result analysis. The binding process can be customized through specifying allowed fields, required fields, custom editors, etc.

Note that there are potential security implications in failing to set an array of allowed fields. In the case of HTTP form POST data for example, malicious clients can attempt to subvert an application by supplying values for fields or properties that do not exist on the form. In some cases this could lead to illegal data being set on command objects or their nested objects. For this reason, it is highly recommended to specify the DataBinder.setAllowedFields allowedFields property on the DataBinder.

The binding results can be examined via the BindingResult interface, extending the Errors interface: see the DataBinder.getBindingResult() method. Missing fields and property access exceptions will be converted to FieldError FieldErrors , collected in the Errors instance, using the following error codes:

  • Missing field error: "required"
  • Type mismatch error: "typeMismatch"
  • Method invocation error: "methodInvocation"

By default, binding errors get resolved through the BindingErrorProcessor strategy, processing for missing fields and property access exceptions: see the DataBinder.setBindingErrorProcessor method. You can override the default strategy if needed, for example to generate different error codes.

Custom validation errors can be added afterwards. You will typically want to resolve such error codes into proper user-visible error messages; this can be achieved through resolving each error via a org.springframework.context.MessageSource , which is able to resolve an ObjectError / FieldError through its org.springframework.context.MessageSource.getMessage(org.springframework.context.MessageSourceResolvablejava.util.Locale) method. The list of message codes can be customized through the MessageCodesResolver strategy: see the DataBinder.setMessageCodesResolver method. DefaultMessageCodesResolver 's javadoc states details on the default resolution rules.

This generic data binder can be used in any kind of environment. It is typically used by Spring web MVC controllers, via the web-specific subclasses org.springframework.web.bind.ServletRequestDataBinder and org.springframework.web.portlet.bind.PortletRequestDataBinder .
author:
   Rod Johnson
author:
   Juergen Hoeller
author:
   Rob Harrop
See Also:   DataBinder.setAllowedFields
See Also:   DataBinder.setRequiredFields
See Also:   DataBinder.registerCustomEditor
See Also:   DataBinder.setMessageCodesResolver
See Also:   DataBinder.setBindingErrorProcessor
See Also:   DataBinder.bind
See Also:   DataBinder.getBindingResult
See Also:   DefaultMessageCodesResolver
See Also:   DefaultBindingErrorProcessor
See Also:   org.springframework.context.MessageSource
See Also:   org.springframework.web.bind.ServletRequestDataBinder



Field Summary
final public static  StringDEFAULT_OBJECT_NAME
    
final protected static  Loglogger
     We'll create a lot of DataBinder instances: Let's use a static logger.

Constructor Summary
public  DataBinder(Object target)
     Create a new DataBinder instance, with default object name.
public  DataBinder(Object target, String objectName)
     Create a new DataBinder instance.

Method Summary
protected  voidapplyPropertyValues(MutablePropertyValues mpvs)
     Apply given property values to the target object.

Default implementation applies all of the supplied property values as bean property values.

public  voidbind(PropertyValues pvs)
     Bind the given property values to this binder's target.

This call can create field errors, representing basic binding errors like a required field (code "required"), or type mismatch between value and bean property (code "typeMismatch").

Note that the given PropertyValues should be a throwaway instance: For efficiency, it will be modified to just contain allowed fields if it implements the MutablePropertyValues interface; else, an internal mutable copy will be created for this purpose.

protected  voidcheckAllowedFields(MutablePropertyValues mpvs)
     Check the given property values against the allowed fields, removing values for fields that are not allowed.
protected  voidcheckRequiredFields(MutablePropertyValues mpvs)
     Check the given property values against the required fields, generating missing field errors where appropriate.
public  Mapclose()
     Close this DataBinder, which may result in throwing a BindException if it encountered any errors.
protected  voiddoBind(MutablePropertyValues mpvs)
     Actual implementation of the binding process, working with the passed-in MutablePropertyValues instance.
public  PropertyEditorfindCustomEditor(Class requiredType, String propertyPath)
    
public  String[]getAllowedFields()
     Return the fields that should be allowed for binding.
public  BindingErrorProcessorgetBindingErrorProcessor()
     Return the strategy for processing binding errors.
public  BindingResultgetBindingResult()
     Return the BindingResult instance created by this DataBinder.
public  String[]getDisallowedFields()
     Return the fields that should not be allowed for binding.
public  BindExceptiongetErrors()
     Return the Errors instance for this data binder.
protected  AbstractPropertyBindingResultgetInternalBindingResult()
     Return the internal BindingResult held by this DataBinder, as AbstractPropertyBindingResult.
public  StringgetObjectName()
     Return the name of the bound object.
protected  ConfigurablePropertyAccessorgetPropertyAccessor()
     Return the underlying PropertyAccessor of this binder's BindingResult.
public  String[]getRequiredFields()
     Return the fields that are required for each binding process.
public  ObjectgetTarget()
     Return the wrapped target object.
public  voidinitBeanPropertyAccess()
     Initialize standard JavaBean property access for this DataBinder.
public  voidinitDirectFieldAccess()
     Initialize direct field access for this DataBinder, as alternative to the default bean property access.
protected  booleanisAllowed(String field)
     Return if the given field is allowed for binding. Invoked for each passed-in property value.

The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality, in the specified lists of allowed fields and disallowed fields.

public  booleanisIgnoreInvalidFields()
     Return whether to ignore invalid fields when binding.
public  booleanisIgnoreUnknownFields()
     Return whether to ignore unknown fields when binding.
public  voidregisterCustomEditor(Class requiredType, PropertyEditor propertyEditor)
    
public  voidregisterCustomEditor(Class requiredType, String field, PropertyEditor propertyEditor)
    
public  voidsetAllowedFields(String[] allowedFields)
     Register fields that should be allowed for binding.
public  voidsetBindingErrorProcessor(BindingErrorProcessor bindingErrorProcessor)
     Set the strategy to use for processing binding errors, that is, required field errors and PropertyAccessExceptions.
public  voidsetDisallowedFields(String[] disallowedFields)
     Register fields that should not be allowed for binding.
public  voidsetExtractOldValueForEditor(boolean extractOldValueForEditor)
     Set whether to extract the old field value when applying a property editor to a new value for a field.
public  voidsetIgnoreInvalidFields(boolean ignoreInvalidFields)
     Set whether to ignore invalid fields, that is, whether to ignore bind parameters that have corresponding fields in the target object which are not accessible (for example because of null values in the nested path).

Default is "false".

public  voidsetIgnoreUnknownFields(boolean ignoreUnknownFields)
     Set whether to ignore unknown fields, that is, whether to ignore bind parameters that do not have corresponding fields in the target object.

Default is "true".

public  voidsetMessageCodesResolver(MessageCodesResolver messageCodesResolver)
     Set the strategy to use for resolving errors into message codes.
public  voidsetRequiredFields(String[] requiredFields)
     Register fields that are required for each binding process.

Field Detail
DEFAULT_OBJECT_NAME
final public static String DEFAULT_OBJECT_NAME(Code)
Default object name used for binding: "target"



logger
final protected static Log logger(Code)
We'll create a lot of DataBinder instances: Let's use a static logger.




Constructor Detail
DataBinder
public DataBinder(Object target)(Code)
Create a new DataBinder instance, with default object name.
Parameters:
  target - target object to bind onto
See Also:   DataBinder.DEFAULT_OBJECT_NAME



DataBinder
public DataBinder(Object target, String objectName)(Code)
Create a new DataBinder instance.
Parameters:
  target - target object to bind onto
Parameters:
  objectName - name of the target object




Method Detail
applyPropertyValues
protected void applyPropertyValues(MutablePropertyValues mpvs)(Code)
Apply given property values to the target object.

Default implementation applies all of the supplied property values as bean property values. By default, unknown fields will be ignored.
Parameters:
  mpvs - the property values to be bound (can be modified)
See Also:   DataBinder.getTarget
See Also:   DataBinder.getPropertyAccessor
See Also:   DataBinder.isIgnoreUnknownFields
See Also:   DataBinder.getBindingErrorProcessor
See Also:   BindingErrorProcessor.processPropertyAccessException




bind
public void bind(PropertyValues pvs)(Code)
Bind the given property values to this binder's target.

This call can create field errors, representing basic binding errors like a required field (code "required"), or type mismatch between value and bean property (code "typeMismatch").

Note that the given PropertyValues should be a throwaway instance: For efficiency, it will be modified to just contain allowed fields if it implements the MutablePropertyValues interface; else, an internal mutable copy will be created for this purpose. Pass in a copy of the PropertyValues if you want your original instance to stay unmodified in any case.
Parameters:
  pvs - property values to bind
See Also:   DataBinder.doBind(org.springframework.beans.MutablePropertyValues)




checkAllowedFields
protected void checkAllowedFields(MutablePropertyValues mpvs)(Code)
Check the given property values against the allowed fields, removing values for fields that are not allowed.
Parameters:
  mpvs - the property values to be bound (can be modified)
See Also:   DataBinder.getAllowedFields
See Also:   DataBinder.isAllowed(String)



checkRequiredFields
protected void checkRequiredFields(MutablePropertyValues mpvs)(Code)
Check the given property values against the required fields, generating missing field errors where appropriate.
Parameters:
  mpvs - the property values to be bound (can be modified)
See Also:   DataBinder.getRequiredFields
See Also:   DataBinder.getBindingErrorProcessor
See Also:   BindingErrorProcessor.processMissingFieldError



close
public Map close() throws BindException(Code)
Close this DataBinder, which may result in throwing a BindException if it encountered any errors. the model Map, containing target object and Errors instance
throws:
  BindException - if there were any errors in the bind operation
See Also:   BindingResult.getModel



doBind
protected void doBind(MutablePropertyValues mpvs)(Code)
Actual implementation of the binding process, working with the passed-in MutablePropertyValues instance.
Parameters:
  mpvs - the property values to bind,as MutablePropertyValues instance
See Also:   DataBinder.checkAllowedFields
See Also:   DataBinder.checkRequiredFields
See Also:   DataBinder.applyPropertyValues



findCustomEditor
public PropertyEditor findCustomEditor(Class requiredType, String propertyPath)(Code)



getAllowedFields
public String[] getAllowedFields()(Code)
Return the fields that should be allowed for binding. array of field names



getBindingErrorProcessor
public BindingErrorProcessor getBindingErrorProcessor()(Code)
Return the strategy for processing binding errors.



getBindingResult
public BindingResult getBindingResult()(Code)
Return the BindingResult instance created by this DataBinder. This allows for convenient access to the binding results after a bind operation. the BindingResult instance, to be treated as BindingResultor as Errors instance (Errors is a super-interface of BindingResult)
See Also:   Errors
See Also:   DataBinder.bind



getDisallowedFields
public String[] getDisallowedFields()(Code)
Return the fields that should not be allowed for binding. array of field names



getErrors
public BindException getErrors()(Code)
Return the Errors instance for this data binder. the Errors instance, to be treated as Errors or as BindExceptionDataBinder.getBindingResult()BindException.BindException(BindingResult)
See Also:   DataBinder.getBindingResult()



getInternalBindingResult
protected AbstractPropertyBindingResult getInternalBindingResult()(Code)
Return the internal BindingResult held by this DataBinder, as AbstractPropertyBindingResult.



getObjectName
public String getObjectName()(Code)
Return the name of the bound object.



getPropertyAccessor
protected ConfigurablePropertyAccessor getPropertyAccessor()(Code)
Return the underlying PropertyAccessor of this binder's BindingResult. To be used by binder subclasses that need property checks.



getRequiredFields
public String[] getRequiredFields()(Code)
Return the fields that are required for each binding process. array of field names



getTarget
public Object getTarget()(Code)
Return the wrapped target object.



initBeanPropertyAccess
public void initBeanPropertyAccess()(Code)
Initialize standard JavaBean property access for this DataBinder.

This is the default; an explicit call just leads to eager initialization.
See Also:   DataBinder.initDirectFieldAccess()




initDirectFieldAccess
public void initDirectFieldAccess()(Code)
Initialize direct field access for this DataBinder, as alternative to the default bean property access.
See Also:   DataBinder.initBeanPropertyAccess()



isAllowed
protected boolean isAllowed(String field)(Code)
Return if the given field is allowed for binding. Invoked for each passed-in property value.

The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality, in the specified lists of allowed fields and disallowed fields. A field matching a disallowed pattern will not be accepted even if it also happens to match a pattern in the allowed list.

Can be overridden in subclasses.
Parameters:
  field - the field to check if the field is allowed
See Also:   DataBinder.setAllowedFields
See Also:   DataBinder.setDisallowedFields
See Also:   org.springframework.util.PatternMatchUtils.simpleMatch(StringString)




isIgnoreInvalidFields
public boolean isIgnoreInvalidFields()(Code)
Return whether to ignore invalid fields when binding.



isIgnoreUnknownFields
public boolean isIgnoreUnknownFields()(Code)
Return whether to ignore unknown fields when binding.



registerCustomEditor
public void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor)(Code)



registerCustomEditor
public void registerCustomEditor(Class requiredType, String field, PropertyEditor propertyEditor)(Code)



setAllowedFields
public void setAllowedFields(String[] allowedFields)(Code)
Register fields that should be allowed for binding. Default is all fields. Restrict this for example to avoid unwanted modifications by malicious users when binding HTTP request parameters.

Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching can be implemented by overriding the isAllowed method.

Alternatively, specify a list of disallowed fields.
Parameters:
  allowedFields - array of field names
See Also:   DataBinder.setDisallowedFields
See Also:   DataBinder.isAllowed(String)
See Also:   org.springframework.web.bind.ServletRequestDataBinder




setBindingErrorProcessor
public void setBindingErrorProcessor(BindingErrorProcessor bindingErrorProcessor)(Code)
Set the strategy to use for processing binding errors, that is, required field errors and PropertyAccessExceptions.

Default is a DefaultBindingErrorProcessor.
See Also:   DefaultBindingErrorProcessor




setDisallowedFields
public void setDisallowedFields(String[] disallowedFields)(Code)
Register fields that should not be allowed for binding. Default is none. Mark fields as disallowed for example to avoid unwanted modifications by malicious users when binding HTTP request parameters.

Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching can be implemented by overriding the isAllowed method.

Alternatively, specify a list of allowed fields.
Parameters:
  disallowedFields - array of field names
See Also:   DataBinder.setAllowedFields
See Also:   DataBinder.isAllowed(String)
See Also:   org.springframework.web.bind.ServletRequestDataBinder




setExtractOldValueForEditor
public void setExtractOldValueForEditor(boolean extractOldValueForEditor)(Code)
Set whether to extract the old field value when applying a property editor to a new value for a field.

Default is "true", exposing previous field values to custom editors. Turn this to "false" to avoid side effects caused by getters.




setIgnoreInvalidFields
public void setIgnoreInvalidFields(boolean ignoreInvalidFields)(Code)
Set whether to ignore invalid fields, that is, whether to ignore bind parameters that have corresponding fields in the target object which are not accessible (for example because of null values in the nested path).

Default is "false". Turn this on to ignore bind parameters for nested objects in non-existing parts of the target object graph.

Note that this setting only applies to binding operations on this DataBinder, not to retrieving values via its DataBinder.getBindingResult() BindingResult .
See Also:   DataBinder.bind




setIgnoreUnknownFields
public void setIgnoreUnknownFields(boolean ignoreUnknownFields)(Code)
Set whether to ignore unknown fields, that is, whether to ignore bind parameters that do not have corresponding fields in the target object.

Default is "true". Turn this off to enforce that all bind parameters must have a matching field in the target object.

Note that this setting only applies to binding operations on this DataBinder, not to retrieving values via its DataBinder.getBindingResult() BindingResult .
See Also:   DataBinder.bind




setMessageCodesResolver
public void setMessageCodesResolver(MessageCodesResolver messageCodesResolver)(Code)
Set the strategy to use for resolving errors into message codes. Applies the given strategy to the underlying errors holder.

Default is a DefaultMessageCodesResolver.
See Also:   BeanPropertyBindingResult.setMessageCodesResolver
See Also:   DefaultMessageCodesResolver




setRequiredFields
public void setRequiredFields(String[] requiredFields)(Code)
Register fields that are required for each binding process.

If one of the specified fields is not contained in the list of incoming property values, a corresponding "missing field" error will be created, with error code "required" (by the default binding error processor).
Parameters:
  requiredFields - array of field names
See Also:   DataBinder.setBindingErrorProcessor
See Also:   DefaultBindingErrorProcessor.MISSING_FIELD_ERROR_CODE




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.