Package org.springframework.validation
Class DefaultBindingErrorProcessor
- java.lang.Object
- org.springframework.validation.DefaultBindingErrorProcessor
- All Implemented Interfaces:
BindingErrorProcessor
public class DefaultBindingErrorProcessor extends Object implements BindingErrorProcessor
DefaultBindingErrorProcessorimplementation.Uses the "required" error code and the field name to resolve message codes for a missing field error.
Creates a
FieldErrorfor eachPropertyAccessExceptiongiven, using thePropertyAccessException'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
Fields Modifier and Type Field Description static StringMISSING_FIELD_ERROR_CODEError code that a missing field error (i.e.
Constructor Summary
Constructors Constructor Description DefaultBindingErrorProcessor()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object[]getArgumentsForBindError(String objectName, String field)Return FieldError arguments for a binding error on the given field.voidprocessMissingFieldError(String missingField, BindingResult bindingResult)Apply the missing field error to the given BindException.voidprocessPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult)Translate the givenPropertyAccessExceptionto an appropriate error registered on the givenErrorsinstance.
Field Detail
MISSING_FIELD_ERROR_CODE
public static final String 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:
- Constant Field Values
Constructor Detail
DefaultBindingErrorProcessor
public DefaultBindingErrorProcessor()
Method Detail
processMissingFieldError
public void processMissingFieldError(String missingField, BindingResult bindingResult)
Description copied from interface:BindingErrorProcessorApply the missing field error to the given BindException.Usually, a field error is created for a missing required field.
- Specified by:
processMissingFieldErrorin 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. TheBindingResultobject features convenience utils such as aresolveMessageCodesmethod to resolve an error code.- See Also:
AbstractBindingResult.addError(org.springframework.validation.ObjectError),AbstractBindingResult.resolveMessageCodes(java.lang.String)
processPropertyAccessException
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult)
Description copied from interface:BindingErrorProcessorTranslate the givenPropertyAccessExceptionto an appropriate error registered on the givenErrorsinstance.Note that two error types are available:
FieldErrorandObjectError. Usually, field errors are created, but in certain situations one might want to create a globalObjectErrorinstead.- Specified by:
processPropertyAccessExceptionin interfaceBindingErrorProcessor- Parameters:
ex- thePropertyAccessExceptionto translatebindingResult- the errors object to add the error(s) to. You can add more than just one error or maybe even ignore it. TheBindingResultobject features convenience utils such as aresolveMessageCodesmethod to resolve an error code.- See Also:
Errors,FieldError,ObjectError,MessageCodesResolver,AbstractBindingResult.addError(org.springframework.validation.ObjectError),AbstractBindingResult.resolveMessageCodes(java.lang.String)
getArgumentsForBindError
protected Object[] getArgumentsForBindError(String objectName, String field)
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:
DefaultMessageSourceResolvable.getArguments(),DefaultMessageSourceResolvable