Top Description Fields Constructors Methods
org.springframework.validation

public abstract Class AbstractBindingResult

extends AbstractErrors
implements BindingResult, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.springframework.validation.BindingResult, org.springframework.validation.Errors
Known Direct Subclasses
org.springframework.validation.AbstractPropertyBindingResult, org.springframework.validation.MapBindingResult
Annotations
@SuppressWarnings:serial
Imports
java.beans.PropertyEditor, java.io.Serializable, java.util.ArrayList, .Collections, .HashMap, .HashSet, .LinkedHashMap, .List, .Map, .Set, org.springframework.beans.PropertyEditorRegistry, org.springframework.lang.Nullable, org.springframework.util.Assert, .ObjectUtils, .StringUtils

Abstract implementation of the BindingResult interface and its super-interface Errors. Encapsulates common management of ObjectErrors and FieldErrors.
Authors
Juergen Hoeller, Rob Harrop
Since
2.0
See Also
Errors

Field Summary

Modifier and TypeField and Description
private final List<ObjectError>
private final Map<String, Class<?>>
private final Map<String, Object>
private MessageCodesResolver
private final String
private final Set<String>

Constructor Summary

AccessConstructor and Description
protected
AbstractBindingResult(String
the name of the target object
objectName
)

Create a new AbstractBindingResult instance.

Method Summary

Modifier and TypeMethod and Description
public void
addAllErrors(Errors
the Errors instance to merge in
errors
)

Overrides default org.springframework.validation.Errors.addAllErrors.

Add all errors from the given Errors instance to this Errors instance.
public void
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public PropertyEditor
findEditor(String
the path of the property (name or nested path), or null if looking for an editor for all properties of the given type
field
,
Class<?>
the type of the property (can be null if a property is given but should be specified in any case for consistency checking)
valueType
)

Implements org.springframework.validation.BindingResult.findEditor.

This implementation delegates to the PropertyEditorRegistry's editor lookup facility, if available.
protected Object

Returns:

the formatted value
formatFieldValue
(String
the field to check
field
,
Object
the value of the field (either a rejected value other than from a binding error, or an actual field value)
value
)

Format the given value for the specified field.

protected abstract Object

Returns:

the current value of the field
getActualFieldValue
(String
the field to check
field
)

Extract the actual field value for the given field.

public List<ObjectError>
getAllErrors()

Overrides default org.springframework.validation.Errors.getAllErrors.

Get all errors, both global and field ones.
public int
getErrorCount()

Overrides default org.springframework.validation.Errors.getErrorCount.

Determine the total number of errors.
public FieldError
getFieldError()

Overrides default org.springframework.validation.Errors.getFieldError.

Get the first error associated with a field, if any.
public FieldError
getFieldError(String
the field name
field
)

Overrides default org.springframework.validation.Errors.getFieldError.

Get the first error associated with the given field, if any.
public List<FieldError>
getFieldErrors()

Implements org.springframework.validation.Errors.getFieldErrors.

Get all errors associated with a field.
public List<FieldError>
getFieldErrors(String
the field name
field
)

Overrides org.springframework.validation.AbstractErrors.getFieldErrors.

Overrides default org.springframework.validation.Errors.getFieldErrors.

Get all errors associated with the given field.
public Class<?>
getFieldType(String
the field name
field
)

Overrides default org.springframework.validation.Errors.getFieldType.

This default implementation determines the type based on the actual field value, if any.
public Object
getFieldValue(String
the field name
field
)

Implements org.springframework.validation.Errors.getFieldValue.

Return the current value of the given field, either the current bean property value or a rejected update from the last binding.
public ObjectError
getGlobalError()

Overrides default org.springframework.validation.Errors.getGlobalError.

Get the first global error, if any.
public List<ObjectError>
public MessageCodesResolver
getMessageCodesResolver()

Return the strategy to use for resolving errors into message codes.

public Map<String, Object>
getModel()

Implements org.springframework.validation.BindingResult.getModel.

Return a model Map for the obtained state, exposing an Errors instance as 'MODEL_KEY_PREFIX + objectName' and the object itself.
public String
getObjectName()

Implements org.springframework.validation.Errors.getObjectName.

Return the name of the bound root object.
public PropertyEditorRegistry
public Object
getRawFieldValue(String
the field to check
field
)

Implements org.springframework.validation.BindingResult.getRawFieldValue.

Extract the raw field value for the given field.
public String[]
getSuppressedFields()

Overrides default org.springframework.validation.BindingResult.getSuppressedFields.

Return the list of fields that were suppressed during the bind process.
public abstract Object
getTarget()

Redeclares org.springframework.validation.BindingResult.getTarget.

Return the wrapped target object.
public boolean
hasErrors()

Overrides default org.springframework.validation.Errors.hasErrors.

Determine if there were any errors.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public void
recordFieldValue(String
the field to record the value for
field
,
Class<?>
the type of the field
type
,
Object
the original value
value
)

Overrides default org.springframework.validation.BindingResult.recordFieldValue.

Record the given value for the specified field.
public void
recordSuppressedField(String field)

Overrides default org.springframework.validation.BindingResult.recordSuppressedField.

Mark the specified disallowed field as suppressed.
public void
reject(String
error code, interpretable as a message key
errorCode
,
Object[]
error arguments, for argument binding via MessageFormat (can be null)
errorArgs
,
String
fallback default message
defaultMessage
)

Implements org.springframework.validation.Errors.reject.

Register a global error for the entire target object, using the given error description.
public void
rejectValue(String
the field name (may be null or empty String)
field
,
String
error code, interpretable as a message key
errorCode
,
Object[]
error arguments, for argument binding via MessageFormat (can be null)
errorArgs
,
String
fallback default message
defaultMessage
)

Implements org.springframework.validation.Errors.rejectValue.

Register a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.
public String[]
resolveMessageCodes(String
the error code to resolve into message codes
errorCode
)

Implements org.springframework.validation.BindingResult.resolveMessageCodes.

Resolve the given error code into message codes.
public String[]
resolveMessageCodes(String
the error code to resolve into message codes
errorCode
,
String
the field to resolve message codes for
field
)

Implements org.springframework.validation.BindingResult.resolveMessageCodes.

Resolve the given error code into message codes for the given field.
public void
setMessageCodesResolver(MessageCodesResolver messageCodesResolver)

Set the strategy to use for resolving errors into message codes.

Inherited from org.springframework.validation.AbstractErrors:
canonicalFieldNamedoSetNestedPathfixedFieldgetNestedPathisMatchingFieldErrorpopNestedPathpushNestedPathsetNestedPathtoString

Field Detail

errorsback to summary
private final List<ObjectError> errors
fieldTypesback to summary
private final Map<String, Class<?>> fieldTypes
fieldValuesback to summary
private final Map<String, Object> fieldValues
messageCodesResolverback to summary
private MessageCodesResolver messageCodesResolver
objectNameback to summary
private final String objectName
suppressedFieldsback to summary
private final Set<String> suppressedFields

Constructor Detail

AbstractBindingResultback to summary
protected AbstractBindingResult(String objectName)

Create a new AbstractBindingResult instance.

Parameters
objectName:String

the name of the target object

See Also
DefaultMessageCodesResolver

Method Detail

addAllErrorsback to summary
public void addAllErrors(Errors errors)

Overrides default org.springframework.validation.Errors.addAllErrors.

Doc from org.springframework.validation.Errors.addAllErrors.

Add all errors from the given Errors instance to this Errors instance.

This is a convenience method to avoid repeated reject(..) calls for merging an Errors instance into another Errors instance.

Note that the passed-in Errors instance is supposed to refer to the same target object, or at least contain compatible errors that apply to the target object of this Errors instance.

The default implementation throws UnsupportedOperationException since not all Errors implementations support #addAllErrors.

Parameters
errors:Errors

the Errors instance to merge in

Annotations
@Override
addErrorback to summary
public void addError(ObjectError error)

Implements org.springframework.validation.BindingResult.addError.

Doc from org.springframework.validation.BindingResult.addError.

Add a custom ObjectError or FieldError to the errors list.

Intended to be used by cooperating strategies such as BindingErrorProcessor.

Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
findEditorback to summary
public PropertyEditor findEditor(String field, Class<?> valueType)

Implements org.springframework.validation.BindingResult.findEditor.

This implementation delegates to the PropertyEditorRegistry's editor lookup facility, if available.

Parameters
field:String

Doc from org.springframework.validation.BindingResult.findEditor.

the path of the property (name or nested path), or null if looking for an editor for all properties of the given type

valueType:Class<?>

Doc from org.springframework.validation.BindingResult.findEditor.

the type of the property (can be null if a property is given but should be specified in any case for consistency checking)

Returns:PropertyEditor

Doc from org.springframework.validation.BindingResult.findEditor.

the registered editor, or null if none

Annotations
@Override
@Nullable
formatFieldValueback to summary
protected Object formatFieldValue(String field, Object value)

Format the given value for the specified field.

The default implementation simply returns the field value as-is.

Parameters
field:String

the field to check

value:Object

the value of the field (either a rejected value other than from a binding error, or an actual field value)

Returns:Object

the formatted value

Annotations
@Nullable
getActualFieldValueback to summary
protected abstract Object getActualFieldValue(String field)

Extract the actual field value for the given field.

Parameters
field:String

the field to check

Returns:Object

the current value of the field

Annotations
@Nullable
getAllErrorsback to summary
public List<ObjectError> getAllErrors()

Overrides default org.springframework.validation.Errors.getAllErrors.

Doc from org.springframework.validation.Errors.getAllErrors.

Get all errors, both global and field ones.

Returns:List<ObjectError>

a list of ObjectError/FieldError instances

Annotations
@Override
getErrorCountback to summary
public int getErrorCount()

Overrides default org.springframework.validation.Errors.getErrorCount.

Doc from org.springframework.validation.Errors.getErrorCount.

Determine the total number of errors.

Annotations
@Override
getFieldErrorback to summary
public FieldError getFieldError()

Overrides default org.springframework.validation.Errors.getFieldError.

Doc from org.springframework.validation.Errors.getFieldError.

Get the first error associated with a field, if any.

Returns:FieldError

the field-specific error, or null

Annotations
@Override
@Nullable
getFieldErrorback to summary
public FieldError getFieldError(String field)

Overrides default org.springframework.validation.Errors.getFieldError.

Doc from org.springframework.validation.Errors.getFieldError.

Get the first error associated with the given field, if any.

Parameters
field:String

the field name

Returns:FieldError

the field-specific error, or null

Annotations
@Override
@Nullable
getFieldErrorsback to summary
public List<FieldError> getFieldErrors()

Implements org.springframework.validation.Errors.getFieldErrors.

Doc from org.springframework.validation.Errors.getFieldErrors.

Get all errors associated with a field.

Returns:List<FieldError>

a List of FieldError instances

Annotations
@Override
getFieldErrorsback to summary
public List<FieldError> getFieldErrors(String field)

Overrides org.springframework.validation.AbstractErrors.getFieldErrors.

Overrides default org.springframework.validation.Errors.getFieldErrors.

Doc from org.springframework.validation.Errors.getFieldErrors.

Get all errors associated with the given field.

Implementations may support not only full field names like "address.street" but also pattern matches like "address.*".

Parameters
field:String

the field name

Returns:List<FieldError>

a List of FieldError instances

Annotations
@Override
getFieldTypeback to summary
public Class<?> getFieldType(String field)

Overrides default org.springframework.validation.Errors.getFieldType.

This default implementation determines the type based on the actual field value, if any. Subclasses should override this to determine the type from a descriptor, even for null values.

Parameters
field:String

Doc from org.springframework.validation.Errors.getFieldType.

the field name

Returns:Class<?>

Doc from org.springframework.validation.Errors.getFieldType.

the type of the field, or null if not determinable

Annotations
@Override
@Nullable
See Also
getActualFieldValue
getFieldValueback to summary
public Object getFieldValue(String field)

Implements org.springframework.validation.Errors.getFieldValue.

Doc from org.springframework.validation.Errors.getFieldValue.

Return the current value of the given field, either the current bean property value or a rejected update from the last binding.

Allows for convenient access to user-specified field values, even if there were type mismatches.

Parameters
field:String

the field name

Returns:Object

the current value of the given field

Annotations
@Override
@Nullable
getGlobalErrorback to summary
public ObjectError getGlobalError()

Overrides default org.springframework.validation.Errors.getGlobalError.

Doc from org.springframework.validation.Errors.getGlobalError.

Get the first global error, if any.

Returns:ObjectError

the global error, or null

Annotations
@Override
@Nullable
getGlobalErrorsback to summary
public List<ObjectError> getGlobalErrors()

Implements org.springframework.validation.Errors.getGlobalErrors.

Doc from org.springframework.validation.Errors.getGlobalErrors.

Get all global errors.

Returns:List<ObjectError>

a list of ObjectError instances

Annotations
@Override
getMessageCodesResolverback to summary
public MessageCodesResolver getMessageCodesResolver()

Return the strategy to use for resolving errors into message codes.

getModelback to summary
public Map<String, Object> getModel()

Implements org.springframework.validation.BindingResult.getModel.

Return a model Map for the obtained state, exposing an Errors instance as 'MODEL_KEY_PREFIX + objectName' and the object itself.

Note that the Map is constructed every time you're calling this method. Adding things to the map and then re-calling this method will not work.

The attributes in the model Map returned by this method are usually included in the ModelAndView for a form view that uses Spring's bind tag, which needs access to the Errors instance.

Annotations
@Override
See Also
getObjectName, MODEL_KEY_PREFIX
getObjectNameback to summary
public String getObjectName()

Implements org.springframework.validation.Errors.getObjectName.

Doc from org.springframework.validation.Errors.getObjectName.

Return the name of the bound root object.

Annotations
@Override
getPropertyEditorRegistryback to summary
public PropertyEditorRegistry getPropertyEditorRegistry()

Implements org.springframework.validation.BindingResult.getPropertyEditorRegistry.

This implementation returns null.

Returns:PropertyEditorRegistry

Doc from org.springframework.validation.BindingResult.getPropertyEditorRegistry.

the PropertyEditorRegistry, or null if none available for this BindingResult

Annotations
@Override
@Nullable
getRawFieldValueback to summary
public Object getRawFieldValue(String field)

Implements org.springframework.validation.BindingResult.getRawFieldValue.

Doc from org.springframework.validation.BindingResult.getRawFieldValue.

Extract the raw field value for the given field. Typically used for comparison purposes.

Parameters
field:String

the field to check

Returns:Object

the current value of the field in its raw form, or null if not known

Annotations
@Override
@Nullable
getSuppressedFieldsback to summary
public String[] getSuppressedFields()

Overrides default org.springframework.validation.BindingResult.getSuppressedFields.

Return the list of fields that were suppressed during the bind process.

Can be used to determine whether any field values were targeting disallowed fields.

Annotations
@Override
See Also
DataBinder#setAllowedFields
getTargetback to summary
public abstract Object getTarget()

Redeclares org.springframework.validation.BindingResult.getTarget.

Return the wrapped target object.

Annotations
@Override
@Nullable
hasErrorsback to summary
public boolean hasErrors()

Overrides default org.springframework.validation.Errors.hasErrors.

Doc from org.springframework.validation.Errors.hasErrors.

Determine if there were any errors.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
recordFieldValueback to summary
public void recordFieldValue(String field, Class<?> type, Object value)

Overrides default org.springframework.validation.BindingResult.recordFieldValue.

Doc from org.springframework.validation.BindingResult.recordFieldValue.

Record the given value for the specified field.

To be used when a target object cannot be constructed, making the original field values available through getFieldValue. In case of a registered error, the rejected value will be exposed for each affected field.

Parameters
field:String

the field to record the value for

type:Class<?>

the type of the field

value:Object

the original value

Annotations
@Override
recordSuppressedFieldback to summary
public void recordSuppressedField(String field)

Overrides default org.springframework.validation.BindingResult.recordSuppressedField.

Mark the specified disallowed field as suppressed.

The data binder invokes this for each field value that was detected to target a disallowed field.

Annotations
@Override
See Also
DataBinder#setAllowedFields
rejectback to summary
public void reject(String errorCode, Object[] errorArgs, String defaultMessage)

Implements org.springframework.validation.Errors.reject.

Doc from org.springframework.validation.Errors.reject.

Register a global error for the entire target object, using the given error description.

Parameters
errorCode:String

error code, interpretable as a message key

errorArgs:Object[]

error arguments, for argument binding via MessageFormat (can be null)

defaultMessage:String

fallback default message

Annotations
@Override
rejectValueback to summary
public void rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage)

Implements org.springframework.validation.Errors.rejectValue.

Doc from org.springframework.validation.Errors.rejectValue.

Register a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.

The field name may be null or empty String to indicate the current object itself rather than a field of it. This may result in a corresponding field error within the nested object graph or a global error if the current object is the top object.

Parameters
field:String

the field name (may be null or empty String)

errorCode:String

error code, interpretable as a message key

errorArgs:Object[]

error arguments, for argument binding via MessageFormat (can be null)

defaultMessage:String

fallback default message

Annotations
@Override
resolveMessageCodesback to summary
public String[] resolveMessageCodes(String errorCode)

Implements org.springframework.validation.BindingResult.resolveMessageCodes.

Doc from org.springframework.validation.BindingResult.resolveMessageCodes.

Resolve the given error code into message codes.

Calls the configured MessageCodesResolver with appropriate parameters.

Parameters
errorCode:String

the error code to resolve into message codes

Returns:String[]

the resolved message codes

Annotations
@Override
resolveMessageCodesback to summary
public String[] resolveMessageCodes(String errorCode, String field)

Implements org.springframework.validation.BindingResult.resolveMessageCodes.

Doc from org.springframework.validation.BindingResult.resolveMessageCodes.

Resolve the given error code into message codes for the given field.

Calls the configured MessageCodesResolver with appropriate parameters.

Parameters
errorCode:String

the error code to resolve into message codes

field:String

the field to resolve message codes for

Returns:String[]

the resolved message codes

Annotations
@Override
setMessageCodesResolverback to summary
public void setMessageCodesResolver(MessageCodesResolver messageCodesResolver)

Set the strategy to use for resolving errors into message codes. Default is DefaultMessageCodesResolver.

See Also
DefaultMessageCodesResolver