public abstract class ValidationUtils
extends java.lang.Object
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 and Description |
---|
ValidationUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
invokeValidator(Validator validator,
java.lang.Object obj,
Errors errors)
|
static void |
invokeValidator(Validator validator,
java.lang.Object obj,
Errors errors,
java.lang.Object... validationHints)
|
static void |
rejectIfEmpty(Errors errors,
java.lang.String field,
java.lang.String errorCode)
Reject the given field with the given error code if the value is empty.
|
static void |
rejectIfEmpty(Errors errors,
java.lang.String field,
java.lang.String errorCode,
java.lang.Object[] errorArgs)
Reject the given field with the given error code and error arguments
if the value is empty.
|
static void |
rejectIfEmpty(Errors errors,
java.lang.String field,
java.lang.String errorCode,
java.lang.Object[] errorArgs,
java.lang.String defaultMessage)
Reject the given field with the given error code, error arguments
and default message if the value is empty.
|
static void |
rejectIfEmpty(Errors errors,
java.lang.String field,
java.lang.String errorCode,
java.lang.String defaultMessage)
Reject the given field with the given error code and default message
if the value is empty.
|
static void |
rejectIfEmptyOrWhitespace(Errors errors,
java.lang.String field,
java.lang.String errorCode)
Reject the given field with the given error code if the value is empty
or just contains whitespace.
|
static void |
rejectIfEmptyOrWhitespace(Errors errors,
java.lang.String field,
java.lang.String errorCode,
java.lang.Object[] errorArgs)
Reject the given field with the given error code and error arguments
if the value is empty or just contains whitespace.
|
static void |
rejectIfEmptyOrWhitespace(Errors errors,
java.lang.String field,
java.lang.String errorCode,
java.lang.Object[] errorArgs,
java.lang.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 void |
rejectIfEmptyOrWhitespace(Errors errors,
java.lang.String field,
java.lang.String errorCode,
java.lang.String defaultMessage)
Reject the given field with the given error code and default message
if the value is empty or just contains whitespace.
|
public static void invokeValidator(Validator validator, java.lang.Object obj, Errors errors)
validator
- the Validator
to be invoked (must not be null
)obj
- the object to bind the parameters toerrors
- the Errors
instance that should store the errors (must not be null
)java.lang.IllegalArgumentException
- if either of the Validator
or Errors
arguments is
null
, or if the supplied Validator
does not support
the validation of the supplied object's typepublic static void invokeValidator(Validator validator, java.lang.Object obj, Errors errors, java.lang.Object... validationHints)
validator
- the Validator
to be invoked (must not be null
)obj
- the object to bind the parameters toerrors
- the Errors
instance that should store the errors (must not be null
)validationHints
- one or more hint objects to be passed to the validation enginejava.lang.IllegalArgumentException
- if either of the Validator
or Errors
arguments is
null
, or if the supplied Validator
does not support
the validation of the supplied object's typepublic static void rejectIfEmpty(Errors errors, java.lang.String field, java.lang.String errorCode)
An 'empty' value in this context means either null
or
the empty string "".
The object whose field is being validated does not need to be passed
in because the Errors
instance can resolve field values by itself
(it will usually hold an internal reference to the target object).
errors
- the Errors
instance to register errors onfield
- the field name to checkerrorCode
- the error code, interpretable as message keypublic static void rejectIfEmpty(Errors errors, java.lang.String field, java.lang.String errorCode, java.lang.String defaultMessage)
An 'empty' value in this context means either null
or
the empty string "".
The object whose field is being validated does not need to be passed
in because the Errors
instance can resolve field values by itself
(it will usually hold an internal reference to the target object).
errors
- the Errors
instance to register errors onfield
- the field name to checkerrorCode
- error code, interpretable as message keydefaultMessage
- fallback default messagepublic static void rejectIfEmpty(Errors errors, java.lang.String field, java.lang.String errorCode, java.lang.Object[] errorArgs)
An 'empty' value in this context means either null
or
the empty string "".
The object whose field is being validated does not need to be passed
in because the Errors
instance can resolve field values by itself
(it will usually hold an internal reference to the target object).
errors
- the Errors
instance to register errors onfield
- the field name to checkerrorCode
- the error code, interpretable as message keyerrorArgs
- the error arguments, for argument binding via MessageFormat
(can be null
)public static void rejectIfEmpty(Errors errors, java.lang.String field, java.lang.String errorCode, java.lang.Object[] errorArgs, java.lang.String defaultMessage)
An 'empty' value in this context means either null
or
the empty string "".
The object whose field is being validated does not need to be passed
in because the Errors
instance can resolve field values by itself
(it will usually hold an internal reference to the target object).
errors
- the Errors
instance to register errors onfield
- the field name to checkerrorCode
- the error code, interpretable as message keyerrorArgs
- the error arguments, for argument binding via MessageFormat
(can be null
)defaultMessage
- fallback default messagepublic static void rejectIfEmptyOrWhitespace(Errors errors, java.lang.String field, java.lang.String errorCode)
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 Errors
instance can resolve field values by itself
(it will usually hold an internal reference to the target object).
errors
- the Errors
instance to register errors onfield
- the field name to checkerrorCode
- the error code, interpretable as message keypublic static void rejectIfEmptyOrWhitespace(Errors errors, java.lang.String field, java.lang.String errorCode, java.lang.String defaultMessage)
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 Errors
instance can resolve field values by itself
(it will usually hold an internal reference to the target object).
errors
- the Errors
instance to register errors onfield
- the field name to checkerrorCode
- the error code, interpretable as message keydefaultMessage
- fallback default messagepublic static void rejectIfEmptyOrWhitespace(Errors errors, java.lang.String field, java.lang.String errorCode, java.lang.Object[] errorArgs)
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 Errors
instance can resolve field values by itself
(it will usually hold an internal reference to the target object).
errors
- the Errors
instance to register errors onfield
- the field name to checkerrorCode
- the error code, interpretable as message keyerrorArgs
- the error arguments, for argument binding via MessageFormat
(can be null
)public static void rejectIfEmptyOrWhitespace(Errors errors, java.lang.String field, java.lang.String errorCode, java.lang.Object[] errorArgs, java.lang.String defaultMessage)
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 Errors
instance can resolve field values by itself
(it will usually hold an internal reference to the target object).
errors
- the Errors
instance to register errors onfield
- the field name to checkerrorCode
- the error code, interpretable as message keyerrorArgs
- the error arguments, for argument binding via MessageFormat
(can be null
)defaultMessage
- fallback default message