Package org.springframework.validation
Class DefaultBindingErrorProcessor
java.lang.Object
org.springframework.validation.DefaultBindingErrorProcessor
- All Implemented Interfaces:
BindingErrorProcessor
Default
BindingErrorProcessor
implementation.
Uses the "required" error code and the field name to resolve message codes for a missing field error.
Creates a FieldError
for each PropertyAccessException
given, using the PropertyAccessException
's error code ("typeMismatch",
"methodInvocation") for resolving message codes.
- Since:
- 1.2
- Author:
- Alef Arendsen, Juergen Hoeller
- See Also:
-
MISSING_FIELD_ERROR_CODE
DataBinder.setBindingErrorProcessor(org.springframework.validation.BindingErrorProcessor)
AbstractBindingResult.addError(org.springframework.validation.ObjectError)
AbstractBindingResult.resolveMessageCodes(java.lang.String)
PropertyAccessException.getErrorCode()
TypeMismatchException.ERROR_CODE
MethodInvocationException.ERROR_CODE
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Object[]
getArgumentsForBindError
(String objectName, String field) Return FieldError arguments for a binding error on the given field.void
processMissingFieldError
(String missingField, BindingResult bindingResult) Apply the missing field error to the given BindException.void
processPropertyAccessException
(PropertyAccessException ex, BindingResult bindingResult) Translate the givenPropertyAccessException
to an appropriate error registered on the givenErrors
instance.
-
Field Details
-
MISSING_FIELD_ERROR_CODE
Error code that a missing field error (i.e. a required field not found in the list of property values) will be registered with: "required".- See Also:
-
-
Constructor Details
-
DefaultBindingErrorProcessor
public DefaultBindingErrorProcessor()
-
-
Method Details
-
processMissingFieldError
Description copied from interface:BindingErrorProcessor
Apply the missing field error to the given BindException.Usually, a field error is created for a missing required field.
- Specified by:
processMissingFieldError
in interfaceBindingErrorProcessor
- Parameters:
missingField
- the field that was missing during bindingbindingResult
- the errors object to add the error(s) to. You can add more than just one error or maybe even ignore it. TheBindingResult
object features convenience utils such as aresolveMessageCodes
method to resolve an error code.- See Also:
-
processPropertyAccessException
Description copied from interface:BindingErrorProcessor
Translate the givenPropertyAccessException
to an appropriate error registered on the givenErrors
instance.Note that two error types are available:
FieldError
andObjectError
. Usually, field errors are created, but in certain situations one might want to create a globalObjectError
instead.- Specified by:
processPropertyAccessException
in interfaceBindingErrorProcessor
- Parameters:
ex
- thePropertyAccessException
to translatebindingResult
- the errors object to add the error(s) to. You can add more than just one error or maybe even ignore it. TheBindingResult
object features convenience utils such as aresolveMessageCodes
method to resolve an error code.- See Also:
-
getArgumentsForBindError
Return FieldError arguments for a binding error on the given field. Invoked for each missing required field and each type mismatch.The default implementation returns a single argument indicating the field name (of type DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes).
- Parameters:
objectName
- the name of the target objectfield
- the field that caused the binding error- Returns:
- the Object array that represents the FieldError arguments
- See Also:
-