Top Description Fields Constructors Methods
org.springframework.validation

public abstract Class ValidationUtils

extends Object
Class Inheritance
Imports
org.apache.commons.logging.Log, .LogFactory, org.springframework.lang.Nullable, org.springframework.util.Assert, .ObjectUtils, .StringUtils

Utility class offering convenient methods for invoking a Validator and for rejecting empty fields.

Checks for an empty field in Validator implementations can become one-liners when using rejectIfEmpty or rejectIfEmptyOrWhitespace.

Authors
Juergen Hoeller, Dmitriy Kopylenko
Since
06.05.2003
See Also
Validator, Errors

Field Summary

Modifier and TypeField and Description
private static final Log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
invokeValidator(Validator
the Validator to be invoked
validator
,
Object
the object to bind the parameters to
target
,
Errors
the Errors instance that should store the errors
errors
)

Invoke the given Validator for the supplied object and Errors instance.

public static void
invokeValidator(Validator
the Validator to be invoked
validator
,
Object
the object to bind the parameters to
target
,
Errors
the Errors instance that should store the errors
errors
,
Object...
one or more hint objects to be passed to the validation engine
validationHints
)

Invoke the given Validator/SmartValidator for the supplied object and Errors instance.

public static void
rejectIfEmpty(Errors
the Errors instance to register errors on
errors
,
String
the field name to check
field
,
String
the error code, interpretable as message key
errorCode
)

Reject the given field with the given error code if the value is empty.

public static void
rejectIfEmpty(Errors
the Errors instance to register errors on
errors
,
String
the field name to check
field
,
String
error code, interpretable as message key
errorCode
,
String
fallback default message
defaultMessage
)

Reject the given field with the given error code and default message if the value is empty.

public static void
rejectIfEmpty(Errors
the Errors instance to register errors on
errors
,
String
the field name to check
field
,
String
the error code, interpretable as message key
errorCode
,
Object[]
the error arguments, for argument binding via MessageFormat (can be null)
errorArgs
)

Reject the given field with the given error code and error arguments if the value is empty.

public static void
rejectIfEmpty(Errors
the Errors instance to register errors on
errors
,
String
the field name to check
field
,
String
the error code, interpretable as message key
errorCode
,
Object[]
the error arguments, for argument binding via MessageFormat (can be null)
errorArgs
,
String
fallback default message
defaultMessage
)

Reject the given field with the given error code, error arguments and default message if the value is empty.

public static void
rejectIfEmptyOrWhitespace(Errors
the Errors instance to register errors on
errors
,
String
the field name to check
field
,
String
the error code, interpretable as message key
errorCode
)

Reject the given field with the given error code if the value is empty or just contains whitespace.

public static void
rejectIfEmptyOrWhitespace(Errors
the Errors instance to register errors on
errors
,
String
the field name to check
field
,
String
the error code, interpretable as message key
errorCode
,
String
fallback default message
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
rejectIfEmptyOrWhitespace(Errors
the Errors instance to register errors on
errors
,
String
the field name to check
field
,
String
the error code, interpretable as message key
errorCode
,
Object[]
the error arguments, for argument binding via MessageFormat (can be null)
errorArgs
)

Reject the given field with the given error code and error arguments if the value is empty or just contains whitespace.

public static void
rejectIfEmptyOrWhitespace(Errors
the Errors instance to register errors on
errors
,
String
the field name to check
field
,
String
the error code, interpretable as message key
errorCode
,
Object[]
the error arguments, for argument binding via MessageFormat (can be null)
errorArgs
,
String
fallback default message
defaultMessage
)

Reject the given field with the given error code, error arguments and default message if the value is empty or just contains whitespace.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
private static final Log logger

Constructor Detail

ValidationUtilsback to summary
public ValidationUtils()

Method Detail

invokeValidatorback to summary
public static void invokeValidator(Validator validator, Object target, Errors errors)

Invoke the given Validator for the supplied object and Errors instance.

Parameters
validator:Validator

the Validator to be invoked

target:Object

the object to bind the parameters to

errors:Errors

the Errors instance that should store the errors

Exceptions
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 type
invokeValidatorback to summary
public static void invokeValidator(Validator validator, Object target, Errors errors, Object... validationHints)

Invoke the given Validator/SmartValidator for the supplied object and Errors instance.

Parameters
validator:Validator

the Validator to be invoked

target:Object

the object to bind the parameters to

errors:Errors

the Errors instance that should store the errors

validationHints:Object[]

one or more hint objects to be passed to the validation engine

Exceptions
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 type
rejectIfEmptyback to summary
public static void rejectIfEmpty(Errors errors, String field, String errorCode)

Reject the given field with the given error code if the value is empty.

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).

Parameters
errors:Errors

the Errors instance to register errors on

field:String

the field name to check

errorCode:String

the error code, interpretable as message key

rejectIfEmptyback to summary
public 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 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).

Parameters
errors:Errors

the Errors instance to register errors on

field:String

the field name to check

errorCode:String

error code, interpretable as message key

defaultMessage:String

fallback default message

rejectIfEmptyback to summary
public static void rejectIfEmpty(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.

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).

Parameters
errors:Errors

the Errors instance to register errors on

field:String

the field name to check

errorCode:String

the error code, interpretable as message key

errorArgs:Object[]

the error arguments, for argument binding via MessageFormat (can be null)

rejectIfEmptyback to summary
public static void rejectIfEmpty(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.

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).

Parameters
errors:Errors

the Errors instance to register errors on

field:String

the field name to check

errorCode:String

the error code, interpretable as message key

errorArgs:Object[]

the error arguments, for argument binding via MessageFormat (can be null)

defaultMessage:String

fallback default message

rejectIfEmptyOrWhitespaceback to summary
public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode)

Reject 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 Errors instance can resolve field values by itself (it will usually hold an internal reference to the target object).

Parameters
errors:Errors

the Errors instance to register errors on

field:String

the field name to check

errorCode:String

the error code, interpretable as message key

rejectIfEmptyOrWhitespaceback to summary
public 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 Errors instance can resolve field values by itself (it will usually hold an internal reference to the target object).

Parameters
errors:Errors

the Errors instance to register errors on

field:String

the field name to check

errorCode:String

the error code, interpretable as message key

defaultMessage:String

fallback default message

rejectIfEmptyOrWhitespaceback to summary
public static void rejectIfEmptyOrWhitespace(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.

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).

Parameters
errors:Errors

the Errors instance to register errors on

field:String

the field name to check

errorCode:String

the error code, interpretable as message key

errorArgs:Object[]

the error arguments, for argument binding via MessageFormat (can be null)

rejectIfEmptyOrWhitespaceback to summary
public static void rejectIfEmptyOrWhitespace(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.

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).

Parameters
errors:Errors

the Errors instance to register errors on

field:String

the field name to check

errorCode:String

the error code, interpretable as message key

errorArgs:Object[]

the error arguments, for argument binding via MessageFormat (can be null)

defaultMessage:String

fallback default message