public class DefaultBindingErrorProcessor extends java.lang.Object implements BindingErrorProcessor
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.
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
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MISSING_FIELD_ERROR_CODE
Error code that a missing field error (i.e.
|
Constructor and Description |
---|
DefaultBindingErrorProcessor() |
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object[] |
getArgumentsForBindError(java.lang.String objectName,
java.lang.String field)
Return FieldError arguments for a binding error on the given field.
|
void |
processMissingFieldError(java.lang.String missingField,
BindingResult bindingResult)
Apply the missing field error to the given BindException.
|
void |
processPropertyAccessException(PropertyAccessException ex,
BindingResult bindingResult)
Translate the given
PropertyAccessException to an appropriate
error registered on the given Errors instance. |
public static final java.lang.String MISSING_FIELD_ERROR_CODE
public void processMissingFieldError(java.lang.String missingField, BindingResult bindingResult)
BindingErrorProcessor
Usually, a field error is created for a missing required field.
processMissingFieldError
in interface BindingErrorProcessor
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.
The BindingResult
object features convenience utils such as
a resolveMessageCodes
method to resolve an error code.AbstractBindingResult.addError(org.springframework.validation.ObjectError)
,
AbstractBindingResult.resolveMessageCodes(java.lang.String)
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult)
BindingErrorProcessor
PropertyAccessException
to an appropriate
error registered on the given Errors
instance.
Note that two error types are available: FieldError
and
ObjectError
. Usually, field errors are created, but in certain
situations one might want to create a global ObjectError
instead.
processPropertyAccessException
in interface BindingErrorProcessor
ex
- the PropertyAccessException
to translatebindingResult
- the errors object to add the error(s) to.
You can add more than just one error or maybe even ignore it.
The BindingResult
object features convenience utils such as
a resolveMessageCodes
method to resolve an error code.Errors
,
FieldError
,
ObjectError
,
MessageCodesResolver
,
AbstractBindingResult.addError(org.springframework.validation.ObjectError)
,
AbstractBindingResult.resolveMessageCodes(java.lang.String)
protected java.lang.Object[] getArgumentsForBindError(java.lang.String objectName, java.lang.String field)
The default implementation returns a single argument indicating the field name (of type DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes).
objectName
- the name of the target objectfield
- the field that caused the binding errorDefaultMessageSourceResolvable.getArguments()
,
DefaultMessageSourceResolvable