Class PortletRequestDataBinder

  extended by org.springframework.validation.DataBinder
      extended by org.springframework.web.bind.WebDataBinder
          extended by org.springframework.web.portlet.bind.PortletRequestDataBinder
All Implemented Interfaces:
PropertyEditorRegistry, TypeConverter

public class PortletRequestDataBinder
extends WebDataBinder

Special DataBinder to perform data binding from portlet 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.

Used by Spring Portlet MVC's BaseCommandController. Note that BaseCommandController and its subclasses allow for easy customization of the binder instances that they use through overriding initBinder.

Can also be used for manual data binding in custom web controllers: for example, in a plain Portlet Controller implementation. Simply instantiate a PortletRequestDataBinder for each binding process, and invoke bind with the current PortletRequest as argument:

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

Juergen Hoeller, John A. Lewis
See Also:
bind(javax.portlet.PortletRequest), DataBinder.registerCustomEditor(java.lang.Class, java.beans.PropertyEditor), DataBinder.setAllowedFields(java.lang.String[]), DataBinder.setRequiredFields(java.lang.String[]), WebDataBinder.setFieldMarkerPrefix(java.lang.String), BaseCommandController.initBinder(javax.portlet.PortletRequest, org.springframework.web.portlet.bind.PortletRequestDataBinder)

Field Summary
Fields inherited from class org.springframework.web.bind.WebDataBinder
Fields inherited from class org.springframework.validation.DataBinder
Constructor Summary
PortletRequestDataBinder(Object target)
          Create a new PortletRequestDataBinder instance, with default object name.
PortletRequestDataBinder(Object target, String objectName)
          Create a new PortletRequestDataBinder instance.
Method Summary
 void bind(javax.portlet.PortletRequest 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.
Methods inherited from class org.springframework.web.bind.WebDataBinder
bindMultipartFiles, checkFieldMarkers, doBind, getEmptyValue, getFieldMarkerPrefix, isBindEmptyMultipartFiles, setBindEmptyMultipartFiles, setFieldMarkerPrefix
Methods inherited from class org.springframework.validation.DataBinder
applyPropertyValues, bind, checkAllowedFields, checkRequiredFields, close, convertIfNecessary, convertIfNecessary, findCustomEditor, getAllowedFields, getBindingErrorProcessor, getBindingResult, getDisallowedFields, getErrors, getInternalBindingResult, getObjectName, getPropertyAccessor, getPropertyEditorRegistry, getRequiredFields, getSimpleTypeConverter, getTarget, getTypeConverter, initBeanPropertyAccess, initDirectFieldAccess, isAllowed, isIgnoreInvalidFields, isIgnoreUnknownFields, registerCustomEditor, registerCustomEditor, setAllowedFields, setBindingErrorProcessor, setDisallowedFields, setExtractOldValueForEditor, setIgnoreInvalidFields, setIgnoreUnknownFields, setMessageCodesResolver, setRequiredFields
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public PortletRequestDataBinder(Object target)
Create a new PortletRequestDataBinder instance, with default object name.

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


public PortletRequestDataBinder(Object target,
                                String objectName)
Create a new PortletRequestDataBinder instance.

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
Method Detail


public void bind(javax.portlet.PortletRequest 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.

request - request with parameters to bind (can be multipart)
See Also:
MultipartActionRequest, MultipartFile, WebDataBinder.bindMultipartFiles(java.util.Map, org.springframework.beans.MutablePropertyValues), DataBinder.bind(org.springframework.beans.PropertyValues)


public void closeNoCatch()
                  throws PortletRequestBindingException
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.

PortletRequestBindingException - subclass of PortletException on any binding problem

Copyright © 2002-2008 The Spring Framework.