Class ValidationUtils
Validator
 and for rejecting empty fields.
 Checks for an empty field in Validator implementations can become
 one-liners when using rejectIfEmpty(org.springframework.validation.Errors, java.lang.String, java.lang.String) or rejectIfEmptyOrWhitespace(org.springframework.validation.Errors, java.lang.String, java.lang.String).
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidinvokeValidator(Validator validator, Object target, Errors errors) static voidinvokeValidator(Validator validator, Object target, Errors errors, Object... validationHints) static voidrejectIfEmpty(Errors errors, String field, String errorCode) Reject the given field with the given error code if the value is empty.static voidrejectIfEmpty(Errors errors, String field, String errorCode, Object[] errorArgs) Reject the given field with the given error code and error arguments if the value is empty.static voidrejectIfEmpty(Errors errors, String field, String errorCode, Object[] errorArgs, String defaultMessage) Reject the given field with the given error code, error arguments and default message if the value is empty.static voidrejectIfEmpty(Errors errors, String field, String errorCode, String defaultMessage) Reject the given field with the given error code and default message if the value is empty.static voidrejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode) Reject the given field with the given error code if the value is empty or just contains whitespace.static voidrejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, Object[] errorArgs) Reject the given field with the given error code and error arguments if the value is empty or just contains whitespace.static voidrejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, Object[] errorArgs, String defaultMessage) Reject the given field with the given error code, error arguments and default message if the value is empty or just contains whitespace.static voidrejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, String defaultMessage) Reject the given field with the given error code and default message if the value is empty or just contains whitespace.
- 
Constructor Details- 
ValidationUtilspublic ValidationUtils()
 
- 
- 
Method Details- 
invokeValidator- Parameters:
- validator- the- Validatorto be invoked
- target- the object to bind the parameters to
- errors- the- Errorsinstance that should store the errors
- Throws:
- IllegalArgumentException- if either of the- Validatoror- Errorsarguments is- null, or if the supplied- Validatordoes not- supportthe validation of the supplied object's type
 
- 
invokeValidatorpublic static void invokeValidator(Validator validator, Object target, Errors errors, @Nullable Object... validationHints) - Parameters:
- validator- the- Validatorto be invoked
- target- the object to bind the parameters to
- errors- the- Errorsinstance that should store the errors
- validationHints- one or more hint objects to be passed to the validation engine
- Throws:
- IllegalArgumentException- if either of the- Validatoror- Errorsarguments is- null, or if the supplied- Validatordoes not- supportthe validation of the supplied object's type
 
- 
rejectIfEmptyReject the given field with the given error code if the value is empty.An 'empty' value in this context means either nullor the empty string "".The object whose field is being validated does not need to be passed in because the Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- Parameters:
- errors- the- Errorsinstance to register errors on
- field- the field name to check
- errorCode- the error code, interpretable as message key
 
- 
rejectIfEmptypublic static void rejectIfEmpty(Errors errors, String field, String errorCode, String defaultMessage) Reject the given field with the given error code and default message if the value is empty.An 'empty' value in this context means either nullor the empty string "".The object whose field is being validated does not need to be passed in because the Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- Parameters:
- errors- the- Errorsinstance to register errors on
- field- the field name to check
- errorCode- error code, interpretable as message key
- defaultMessage- fallback default message
 
- 
rejectIfEmptyReject the given field with the given error code and error arguments if the value is empty.An 'empty' value in this context means either nullor the empty string "".The object whose field is being validated does not need to be passed in because the Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- Parameters:
- errors- the- Errorsinstance to register errors on
- field- the field name to check
- errorCode- the error code, interpretable as message key
- errorArgs- the error arguments, for argument binding via MessageFormat (can be- null)
 
- 
rejectIfEmptypublic static void rejectIfEmpty(Errors errors, String field, String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) Reject the given field with the given error code, error arguments and default message if the value is empty.An 'empty' value in this context means either nullor the empty string "".The object whose field is being validated does not need to be passed in because the Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- Parameters:
- errors- the- Errorsinstance to register errors on
- field- the field name to check
- errorCode- the error code, interpretable as message key
- errorArgs- the error arguments, for argument binding via MessageFormat (can be- null)
- defaultMessage- fallback default message
 
- 
rejectIfEmptyOrWhitespaceReject the given field with the given error code if the value is empty or just contains whitespace.An 'empty' value in this context means either null, the empty string "", or consisting wholly of whitespace.The object whose field is being validated does not need to be passed in because the Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- Parameters:
- errors- the- Errorsinstance to register errors on
- field- the field name to check
- errorCode- the error code, interpretable as message key
 
- 
rejectIfEmptyOrWhitespacepublic static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, String defaultMessage) Reject the given field with the given error code and default message if the value is empty or just contains whitespace.An 'empty' value in this context means either null, the empty string "", or consisting wholly of whitespace.The object whose field is being validated does not need to be passed in because the Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- Parameters:
- errors- the- Errorsinstance to register errors on
- field- the field name to check
- errorCode- the error code, interpretable as message key
- defaultMessage- fallback default message
 
- 
rejectIfEmptyOrWhitespacepublic static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, @Nullable Object[] errorArgs) Reject the given field with the given error code and error arguments if the value is empty or just contains whitespace.An 'empty' value in this context means either null, the empty string "", or consisting wholly of whitespace.The object whose field is being validated does not need to be passed in because the Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- Parameters:
- errors- the- Errorsinstance to register errors on
- field- the field name to check
- errorCode- the error code, interpretable as message key
- errorArgs- the error arguments, for argument binding via MessageFormat (can be- null)
 
- 
rejectIfEmptyOrWhitespacepublic static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) Reject the given field with the given error code, error arguments and default message if the value is empty or just contains whitespace.An 'empty' value in this context means either null, the empty string "", or consisting wholly of whitespace.The object whose field is being validated does not need to be passed in because the Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- Parameters:
- errors- the- Errorsinstance to register errors on
- field- the field name to check
- errorCode- the error code, interpretable as message key
- errorArgs- the error arguments, for argument binding via MessageFormat (can be- null)
- defaultMessage- fallback default message
 
 
-