public class

WebRequestDataBinder

extends WebDataBinder
java.lang.Object
   ↳ org.springframework.validation.DataBinder
     ↳ org.springframework.web.bind.WebDataBinder
       ↳ org.springframework.web.bind.support.WebRequestDataBinder

Class Overview

Special DataBinder to perform data binding from web request parameters to JavaBeans, including support for multipart files.

See the DataBinder/WebDataBinder superclasses for customization options, which include specifying allowed/required fields, and registering custom property editors.

Can also used for manual data binding in custom web controllers or interceptors that build on Spring's WebRequest abstraction: e.g. in a WebRequestInterceptor implementation. Simply instantiate a WebRequestDataBinder for each binding process, and invoke bind with the current WebRequest as argument:

 MyBean myBean = new MyBean();
 // apply binder to custom target object
 WebRequestDataBinder binder = new WebRequestDataBinder(myBean);
 // register custom editors, if desired
 binder.registerCustomEditor(...);
 // trigger actual binding of request parameters
 binder.bind(request);
 // optionally evaluate binding errors
 Errors errors = binder.getErrors();
 ...

Summary

[Expand]
Inherited Constants
From class org.springframework.web.bind.WebDataBinder
From class org.springframework.validation.DataBinder
[Expand]
Inherited Fields
From class org.springframework.validation.DataBinder
Public Constructors
WebRequestDataBinder(Object target)
Create a new WebRequestDataBinder instance, with default object name.
WebRequestDataBinder(Object target, String objectName)
Create a new WebRequestDataBinder instance.
Public Methods
void bind(WebRequest request)
Bind the parameters of the given request to this binder's target, also binding multipart files in case of a multipart request.
void closeNoCatch()
Treats errors as fatal.
[Expand]
Inherited Methods
From class org.springframework.web.bind.WebDataBinder
From class org.springframework.validation.DataBinder
From class java.lang.Object
From interface org.springframework.beans.PropertyEditorRegistry
From interface org.springframework.beans.TypeConverter

Public Constructors

public WebRequestDataBinder (Object target)

Create a new WebRequestDataBinder instance, with default object name.

Parameters
target the target object to bind onto (or null if the binder is just used to convert a plain parameter value)

public WebRequestDataBinder (Object target, String objectName)

Create a new WebRequestDataBinder instance.

Parameters
target the target object to bind onto (or null if the binder is just used to convert a plain parameter value)
objectName the name of the target object

Public Methods

public void bind (WebRequest request)

Bind the parameters of the given request to this binder's target, also binding multipart files in case of a multipart request.

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").

Multipart files are bound via their parameter name, just like normal HTTP parameters: i.e. "uploadedFile" to an "uploadedFile" bean property, invoking a "setUploadedFile" setter method.

The type of the target property for a multipart file can be MultipartFile, byte[], or String. The latter two receive the contents of the uploaded file; all metadata like original file name, content type, etc are lost in those cases.

Parameters
request request with parameters to bind (can be multipart)

public void closeNoCatch ()

Treats errors as fatal.

Use this method only if it's an error if the input isn't valid. This might be appropriate if all input is from dropdowns, for example.

Throws
BindException if binding errors have been encountered