Package org.apache.struts.validator
Class FieldChecks
java.lang.Object
org.apache.struts.validator.FieldChecks
- All Implemented Interfaces:
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
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static boolean
Returntrue
if the specified object is a String or anull
value.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.static Object
validateByteLocale
(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 Object
validateCreditCard
(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) Checks if the field is a valid credit card number.static Object
validateDate
(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) Checks if the field is a valid date.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.static Object
validateDoubleLocale
(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 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).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.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.static Object
validateFloatLocale
(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 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).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.static Object
validateIntegerLocale
(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 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).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.static Object
validateLongLocale
(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 boolean
validateLongRange
(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 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.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.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.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.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.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.static Object
validateShortLocale
(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 boolean
validateUrl
(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) Checks if a field has a valid url.
-
Field Details
-
FIELD_TEST_NULL
- See Also:
-
FIELD_TEST_NOTNULL
- See Also:
-
FIELD_TEST_EQUAL
- See Also:
-
-
Constructor Details
-
FieldChecks
public FieldChecks()
-
-
Method Details
-
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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if meets stated requirements, 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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if field matches mask, false otherwise.
-
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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, false otherwise.
-
validateByteLocale
public static Object validateByteLocale(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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, 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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, false otherwise.
-
validateShortLocale
public static Object validateShortLocale(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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, 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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, false otherwise.
-
validateIntegerLocale
public static Object validateIntegerLocale(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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, 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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, false otherwise.
-
validateLongLocale
public static Object validateLongLocale(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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, false otherwise.
-
validateFloatLocale
public static Object validateFloatLocale(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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, false otherwise.
-
validateDoubleLocale
public static Object validateDoubleLocale(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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
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 formatjava.text.SimpleDateFormat
. If the field has a datePatternStrict variable, that will be used to formatjava.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 tofalse
for all variations.- Parameters:
bean
- The bean validation is being performed on.va
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, false otherwise.
-
validateLongRange
public static boolean validateLongRange(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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- True if in range, 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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- True if in range, 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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- True if in range, 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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- True if in range, 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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- true if valid, 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
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- True if valid, 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. ANull
will be considered an error.- Parameters:
bean
- The bean validation is being performed on.va
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
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. ANull
will be considered an error.- Parameters:
bean
- The bean validation is being performed on.va
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- True if stated conditions met.
-
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.- Variable
allow2slashes
can be set totrue
orfalse
to control whether two slashes are allowed - default isfalse
(i.e. two slashes are NOT allowed). - Variable
nofragments
can be set totrue
orfalse
to control whether fragments are allowed - default isfalse
(i.e. fragments ARE allowed). - Variable
allowallschemes
can be set totrue
orfalse
to control if all schemes are allowed - default isfalse
(i.e. all schemes are NOT allowed). - Variable
schemes
can be set to a comma delimited list of valid schemes. This value is ignored ifallowallschemes
is set totrue
. Default schemes allowed are "http", "https" and "ftp" if this variable is not specified.
- Parameters:
bean
- The bean validation is being performed on.va
- TheValidatorAction
that is currently being performed.field
- TheField
object associated with the current field being validated.errors
- TheActionMessages
object to add errors to if any validation errors occur.validator
- TheValidator
instance, used to access other field values.request
- Current request object.- Returns:
- True if valid, false otherwise.
- Variable
-
isString
Returntrue
if the specified object is a String or anull
value.- Parameters:
o
- Object to be tested- Returns:
- The string value
-