|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.validation.DataBinder
Binder that allows for binding property values to a target object. The binding process can be customized through specifying allowed fields, required fields, and custom editors.
The binding results can be examined via the Errors interface, available as BindException instance. Missing field errors and property access exceptions will be converted to FieldErrors, collected in the Errors instance. Custom validation errors can be added afterwards.
This generic data binder can be used in any sort of environment. It is heavily used by Spring's web binding features, via the subclass ServletRequestDataBinder.
bind(org.springframework.beans.PropertyValues)
,
getErrors()
,
ServletRequestDataBinder
Field Summary | |
static java.lang.String |
MISSING_FIELD_ERROR_CODE
|
Constructor Summary | |
DataBinder(java.lang.Object target,
java.lang.String objectName)
Create a new DataBinder instance. |
Method Summary | |
void |
bind(PropertyValues pvs)
Bind the given property values to this binder's target. |
java.util.Map |
close()
Close this DataBinder, which may result in throwing a BindException if it encountered any errors |
protected BindException |
createErrors(java.lang.Object target,
java.lang.String objectName)
Create a new Errors instance for this data binder. |
java.lang.String[] |
getAllowedFields()
Return the fields that should be allowed for binding. |
BindException |
getErrors()
Return the Errors instance for this data binder. |
java.lang.String |
getObjectName()
Return the name of the bound object. |
java.lang.String[] |
getRequiredFields()
Return the fields that are required for each binding process. |
java.lang.Object |
getTarget()
Return the wrapped target object. |
protected boolean |
isAllowed(java.lang.String field)
Return if the given field is allowed for binding. |
void |
registerCustomEditor(java.lang.Class requiredType,
java.beans.PropertyEditor propertyEditor)
Register the given custom property editor for all properties of the given type. |
void |
registerCustomEditor(java.lang.Class requiredType,
java.lang.String field,
java.beans.PropertyEditor propertyEditor)
Register the given custom property editor for the given type and field, or for all fields of the given type. |
void |
setAllowedFields(java.lang.String[] allowedFields)
Register fields that should be allowed for binding. |
void |
setRequiredFields(java.lang.String[] requiredFields)
Register fields that are required for each binding process. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String MISSING_FIELD_ERROR_CODE
Constructor Detail |
public DataBinder(java.lang.Object target, java.lang.String objectName)
target
- target object to bind ontoobjectName
- name of the target objectMethod Detail |
protected BindException createErrors(java.lang.Object target, java.lang.String objectName)
target
- target object to bind ontoobjectName
- name of the target object
close()
public java.lang.Object getTarget()
public java.lang.String getObjectName()
public BindException getErrors()
Errors
public void setAllowedFields(java.lang.String[] allowedFields)
allowedFields
- array of field namesServletRequestDataBinder
public java.lang.String[] getAllowedFields()
public void setRequiredFields(java.lang.String[] requiredFields)
requiredFields
- array of field namespublic java.lang.String[] getRequiredFields()
public void registerCustomEditor(java.lang.Class requiredType, java.beans.PropertyEditor propertyEditor)
requiredType
- type of the propertypropertyEditor
- editor to registerpublic void registerCustomEditor(java.lang.Class requiredType, java.lang.String field, java.beans.PropertyEditor propertyEditor)
requiredType
- type of the property, can be null if a field is
given but should be specified in any case for consistency checkingfield
- name of the field (can also be a nested path), or
null if registering an editor for all fields of the given typepropertyEditor
- editor to registerpublic void bind(PropertyValues pvs)
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.
pvs
- property values to bind.protected boolean isAllowed(java.lang.String field)
The default implementation checks for "xxx*" and "*xxx" matches. Can be overridden in subclasses.
If the field is found in the allowedFields array as direct match, this method will not be invoked.
field
- the field to check
setAllowedFields(java.lang.String[])
public java.util.Map close() throws BindException
BindException
- if there were any errors in the bind operationBindException.getModel()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |