org.springframework.web.bind
Class ServletRequestDataBinder

java.lang.Object
  extended byorg.springframework.validation.DataBinder
      extended byorg.springframework.web.bind.ServletRequestDataBinder

public class ServletRequestDataBinder
extends DataBinder

Use this class to perform manual data binding from servlet request parameters to JavaBeans, including support for multipart files.

Author:
Rod Johnson, Juergen Hoeller

Field Summary
 
Fields inherited from class org.springframework.validation.DataBinder
MISSING_FIELD_ERROR_CODE
 
Constructor Summary
ServletRequestDataBinder(java.lang.Object target, java.lang.String name)
          Create a new DataBinder instance.
 
Method Summary
 void bind(javax.servlet.ServletRequest 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.
 void setBindEmptyMultipartFiles(boolean bindEmptyMultipartFiles)
          Set whether to bind empty MultipartFile parameters.
 
Methods inherited from class org.springframework.validation.DataBinder
bind, close, createErrors, getAllowedFields, getErrors, getObjectName, getRequiredFields, getTarget, isAllowed, registerCustomEditor, registerCustomEditor, setAllowedFields, setRequiredFields
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletRequestDataBinder

public ServletRequestDataBinder(java.lang.Object target,
                                java.lang.String name)
Create a new DataBinder instance.

Parameters:
target - target object to bind onto
name - name of the target object
Method Detail

setBindEmptyMultipartFiles

public void setBindEmptyMultipartFiles(boolean bindEmptyMultipartFiles)
Set whether to bind empty MultipartFile parameters. Default is true.

Turn this off if you want to keep an already bound MultipartFile when the user resubmits the form without choosing a different file. Else, the already bound MultipartFile will be replaced by an empty MultipartFile holder.


bind

public void bind(javax.servlet.ServletRequest 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)
See Also:
MultipartHttpServletRequest, MultipartFile

closeNoCatch

public void closeNoCatch()
                  throws ServletRequestBindingException
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:
ServletRequestBindingException - subclass of ServletException on any binding problem


Copyright (C) 2003-2004 The Spring Framework Project.