org.apache.struts.validator

Class FieldChecks

public class FieldChecks extends Object implements Serializable

This class contains the default validations that are used in the validator-rules.xml file.

In general passing in a null or blank will return a null Object or a false boolean. However, nulls and blanks do not result in an error being added to the errors.

Since: Struts 1.1

Field Summary
static StringFIELD_TEST_EQUAL
static StringFIELD_TEST_NOTNULL
static StringFIELD_TEST_NULL
static Loglog
Commons Logging instance.
Method Summary
protected static booleanisString(Object o)
Return true if the specified object is a String or a null value.
static ObjectvalidateByte(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a byte primitive.
static ObjectvalidateCreditCard(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field is a valid credit card number.
static ObjectvalidateDate(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field is a valid date.
static ObjectvalidateDouble(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a double primitive.
static booleanvalidateDoubleRange(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a fields value is within a range (min & max specified in the vars attribute).
static booleanvalidateEmail(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a field has a valid e-mail address.
static ObjectvalidateFloat(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a float primitive.
static booleanvalidateFloatRange(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a fields value is within a range (min & max specified in the vars attribute).
static ObjectvalidateInteger(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to an int primitive.
static booleanvalidateIntRange(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a fields value is within a range (min & max specified in the vars attribute).
static ObjectvalidateLong(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a long primitive.
static booleanvalidateMask(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field matches the regular expression in the field's mask attribute.
static booleanvalidateMaxLength(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field's length is less than or equal to the maximum value.
static booleanvalidateMinLength(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field's length is greater than or equal to the minimum value.
static booleanvalidateRequired(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field isn't null and length of the field is greater than zero not including whitespace.
static booleanvalidateRequiredIf(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field isn't null based on the values of other fields.
static ObjectvalidateShort(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a short primitive.
static booleanvalidateUrl(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a field has a valid url.

Field Detail

FIELD_TEST_EQUAL

public static final String FIELD_TEST_EQUAL

FIELD_TEST_NOTNULL

public static final String FIELD_TEST_NOTNULL

FIELD_TEST_NULL

public static final String FIELD_TEST_NULL

log

private static final Log log
Commons Logging instance.

Method Detail

isString

protected static boolean isString(Object o)
Return true if the specified object is a String or a null value.

Parameters: o Object to be tested

Returns: The string value

validateByte

public static Object validateByte(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a byte primitive.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if valid, false otherwise.

validateCreditCard

public static Object validateCreditCard(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field is a valid credit card number.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if valid, false otherwise.

validateDate

public static Object validateDate(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field is a valid date. If the field has a datePattern variable, that will be used to format java.text.SimpleDateFormat. If the field has a datePatternStrict variable, that will be used to format java.text.SimpleDateFormat and the length will be checked so '2/12/1999' will not pass validation with the format 'MM/dd/yyyy' because the month isn't two digits. If no datePattern variable is specified, then the field gets the DateFormat.SHORT format for the locale. The setLenient method is set to false for all variations.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if valid, false otherwise.

validateDouble

public static Object validateDouble(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a double primitive.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if valid, false otherwise.

validateDoubleRange

public static boolean validateDoubleRange(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a fields value is within a range (min & max specified in the vars attribute).

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: True if in range, false otherwise.

validateEmail

public static boolean validateEmail(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a field has a valid e-mail address.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: True if valid, false otherwise.

validateFloat

public static Object validateFloat(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a float primitive.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if valid, false otherwise.

validateFloatRange

public static boolean validateFloatRange(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a fields value is within a range (min & max specified in the vars attribute).

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: True if in range, false otherwise.

validateInteger

public static Object validateInteger(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to an int primitive.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if valid, false otherwise.

validateIntRange

public static boolean validateIntRange(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a fields value is within a range (min & max specified in the vars attribute).

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: True if in range, false otherwise.

validateLong

public static Object validateLong(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a long primitive.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if valid, false otherwise.

validateMask

public static boolean validateMask(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field matches the regular expression in the field's mask attribute.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if field matches mask, false otherwise.

validateMaxLength

public static boolean validateMaxLength(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field's length is less than or equal to the maximum value. A Null will be considered an error.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: True if stated conditions met.

validateMinLength

public static boolean validateMinLength(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field's length is greater than or equal to the minimum value. A Null will be considered an error.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: True if stated conditions met.

validateRequired

public static boolean validateRequired(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field isn't null and length of the field is greater than zero not including whitespace.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if meets stated requirements, false otherwise.

validateRequiredIf

public static boolean validateRequiredIf(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field isn't null based on the values of other fields.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if meets stated requirements, false otherwise.

validateShort

public static Object validateShort(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if the field can safely be converted to a short primitive.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: true if valid, false otherwise.

validateUrl

public static boolean validateUrl(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request)
Checks if a field has a valid url. Four optional variables can be specified to configure url validation.

Parameters: bean The bean validation is being performed on. va The ValidatorAction that is currently being performed. field The Field object associated with the current field being validated. errors The ActionMessages object to add errors to if any validation errors occur. validator The Validator instance, used to access other field values. request Current request object.

Returns: True if valid, false otherwise.

Copyright B) 2000-2007 - The Apache Software Foundation