org.springframework.validation
Class ValidationUtils

java.lang.Object
  extended by org.springframework.validation.ValidationUtils

public abstract class ValidationUtils
extends Object

This utility class offers convenient methods for invoking a Validator and for rejecting empty fields. Empty field checks in Validator implementations can become one-liners.

Since:
06.05.2003
Author:
Juergen Hoeller, Dmitriy Kopylenko
See Also:
Validator, Errors

Constructor Summary
ValidationUtils()
           
 
Method Summary
static void invokeValidator(Validator validator, Object obj, Errors errors)
          Invoke the given validator for the given object and Errors instance.
static void rejectIfEmpty(Errors errors, String field, String errorCode)
          Reject the given field with the given error code and message if the value is empty.
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 message if the value is empty.
static void rejectIfEmpty(Errors errors, String field, String errorCode, String defaultMessage)
          Reject the given field with the given error code and message if the value is empty.
static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode)
          Reject the given field with the given error code and message if the value is empty or just contains whitespace.
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 message if the value is empty or just contains whitespace.
static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, String defaultMessage)
          Reject the given field with the given error code and message if the value is empty or just contains whitespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValidationUtils

public ValidationUtils()
Method Detail

invokeValidator

public static void invokeValidator(Validator validator,
                                   Object obj,
                                   Errors errors)
Invoke the given validator for the given object and Errors instance.

Parameters:
validator - validator to be invoked, or null if no validation
obj - object to bind the parameters to
errors - Errors instance that should store the errors

rejectIfEmpty

public static void rejectIfEmpty(Errors errors,
                                 String field,
                                 String errorCode)
Reject the given field with the given error code and message if the value is empty.

The object to validate does not have to be passed in, as the Errors instance allows to check field values (it will usually hold an internal reference to the target object).

Parameters:
errors - Errors instance to register errors on
field - the field name to check
errorCode - error code, interpretable as message key

rejectIfEmpty

public static void rejectIfEmpty(Errors errors,
                                 String field,
                                 String errorCode,
                                 String defaultMessage)
Reject the given field with the given error code and message if the value is empty.

The object to validate does not have to be passed in, as the Errors instance allows to check field values (it will usually hold an internal reference to the target object).

Parameters:
errors - Errors instance to register errors on
field - the field name to check
errorCode - error code, interpretable as message key
defaultMessage - fallback default message

rejectIfEmpty

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 message if the value is empty.

The object to validate does not have to be passed in, as the Errors instance allows to check field values (it will usually hold an internal reference to the target object).

Parameters:
errors - Errors instance to register errors on
field - the field name to check
errorCode - error code, interpretable as message key
errorArgs - error arguments, for argument binding via MessageFormat (can be null)
defaultMessage - fallback default message

rejectIfEmptyOrWhitespace

public static void rejectIfEmptyOrWhitespace(Errors errors,
                                             String field,
                                             String errorCode)
Reject the given field with the given error code and message if the value is empty or just contains whitespace.

The object to validate does not have to be passed in, as the Errors instance allows to check field values (it will usually hold an internal reference to the target object).

Parameters:
errors - Errors instance to register errors on
field - the field name to check
errorCode - error code, interpretable as message key

rejectIfEmptyOrWhitespace

public static void rejectIfEmptyOrWhitespace(Errors errors,
                                             String field,
                                             String errorCode,
                                             String defaultMessage)
Reject the given field with the given error code and message if the value is empty or just contains whitespace.

The object to validate does not have to be passed in, as the Errors instance allows to check field values (it will usually hold an internal reference to the target object).

Parameters:
errors - Errors instance to register errors on
field - the field name to check
errorCode - error code, interpretable as message key
defaultMessage - fallback default message

rejectIfEmptyOrWhitespace

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 message if the value is empty or just contains whitespace.

The object to validate does not have to be passed in, as the Errors instance allows to check field values (it will usually hold an internal reference to the target object).

Parameters:
errors - Errors instance to register errors on
field - the field name to check
errorCode - error code, interpretable as message key
errorArgs - error arguments, for argument binding via MessageFormat (can be null)
defaultMessage - fallback default message


Copyright (c) 2002-2006 The Spring Framework Project.