jp.terasoluna.fw.web.struts.form
Class FieldChecksEx

java.lang.Object
  Extend the above org.apache.struts.validator.FieldChecks
      Extend the above jp.terasoluna.fw.web.struts.form.FieldChecksEx
All implemented interfaces:
java.io.Serializable

public class FieldChecksEx
extends org.apache.struts.validator.FieldChecks

Validator Additional rule class.

Input check class wherein FieldChecks provided by Struts is extended.
Following are the extension rules of FieldChecksEx.

Validation name
Client check
Method name
Rule name(Described in validation-rules.xml)
Overview
Alphanumeric character check
Y
validateAlphaNumericString() alphaNumericString Check if field value consists of only half-width alphanumeric characters.
Uppercase alphanumeric character check
Y
validateCapAlphaNumericString() capAlphaNumericString Check if value consists of only uppercase half-width alphanumeric characters.
Field numeric value check
Y
validateNumber() number Check if field value is the numeric value.
Half-width kana character check
Y
validateHankakuKanaString() hankakuKanaString Check if field value consists of only half-width kana.
Half-width character check
Y
validateHankakuString() hankakuString Check if field value consists of only half-width characters.
Full-width character check
Y
validateZenkakuString() zenkakuString Check if field value consists of only full-width characters.
Full-width kana character check
Y
validateZenkakuKanaString() zenkakuKanaString Check if field value consists of only full-width kana characters.
Input prohibited character check
N
validateProhibited() prohibited Check if field value does not include input prohibited characters.
String length match check
Y
validateStringLength() stringLength Check if the field value matches with the specified string length.
Numeric string check
Y
validateNumericString() numericString Check if field value consists of only numeric characters.
Byte length check
N
validateByteLength() byteLength Check if byte length of field value matches with the specified length.
Byte range check
N
validateByteRange() byteRange Check if the byte length of field value is within the specified range.
Date range check
Y
validateDateRange() dateRange Check if the date of field value is within the specified range.
Multiple field check
N
validateMultiField() multiField Check the correlation between multiple fields.
Array/collection type field all elements check
N
validateArraysIndex() (Decided by <depend> element of validation.xml) Perform input check specified in "depends" attribute for all the field values of array and collection type.

For details of field check, refer to description of each method.
For using the extended Validator, it is necessary to create the definition file ( validation.xml ) wherein the validation contents are described for each action.

In check rules other than mandatory check, when only the string with half-width space is passed as input value, it is not considered as error. For considering it as error, it should be either combined with mandatory check or half-width space check should be added.

Individual Field Validation

In the name attribute of <form> element in <formset>tag, specify the path name of action defined in struts-config.xml.
When it is not specified, the validation is not performed for the corresponding action path. Specify target field name in property attribute of <field> element and specify validation rule name defined in validation-rules.xml in depends attribute. While performing multiple validations (mandatory input and length etc) in one form, specify them with comma separator.
For one field, only one error message is output. (When the mandatory input and length check, both are violated, either of the one error is output.)

Description example of validation.xml(Individual Field Validation)
  <formset>
    ...
    <!-- Individual Field Validation -->
    <form name="/logon">
      <field property="companyId"
          depends="required,alphaNumericString,maxlength">
        <arg0 key="logon.companyId"/>
        <arg1 key="${var:maxlength}" resource="false"/>
        <var>
          <var-name>maxlength</var-name>
          <var-value>10</var-value>
        </var>
      </field>
    </form>
    ...
  </formset>
 
List validation of array and collection type

Following points are extended in the list validation of array and collection type.

Same as Individual Field Validation, <form> element is created in validation.xml. However, following settings are necessary to perform list validation of array and collection type.
  1. For list display of array and collection, always specify the field name (present inside the form) in property attribute. . In property name, it is possible to specify the nested property name according to the JXPathIndexedBeanWrapperImpl specifications.
  2. Rule specified by <depends> must use the rule names in validation-rules.xml with Array in the end.
  3. FormEx interface should be implemented by the form to be validated.
Rules that correspond to list validation of array and collection type are as follows.

Description example of validation.xml(Validation of array and collection type list display)
  <formset>
    ...
    <!-- Validation confirmation of array and collection type list display -->
    <form name="/isValid">
      <field property="codeArray"
          depends="requiredArray,alphaNumericStringArray">
        <arg0 <b>key="##INDEX" resource="false"</b>/>
        <arg1 key="sampleValidate.codeArray"/>
      </field>
    </form>
    ...
  </formset>
 

For embedding the index number of array and collection type into the error message, specify charcter string "##INDEX" in any of the key of <arg0~3> element and change the <resource> element to "false".
Same as Individual Field Validation, while performing multiple validations in <depends>, multiple validation rules can be specified by using comma separator.
For the form wherein Validator framework is used, refer to DynaValidatorActionFormEx , ValidatorActionFormEx .

See Also:
FormEx, DynaValidatorActionFormEx, ValidatorActionFormEx, JXPathIndexedBeanWrapperImpl, Serialized form

Field Summary
protected static java.lang.String HANKAKU_KANA_LIST_KEY
          Key that fetches the half-width character table defined in ApplicationResourcesfile.
protected static java.lang.String hankakuKanaList
          It is half-width kana string.
static java.lang.String INDEX
          Index value of array index type field.
private static org.apache.commons.logging.Log log
          Log class.
private static long serialVersionUID
          Serial version ID.
protected static java.lang.String ZENKAKU_BEGIN_U00_LIST
          Full-width string that exists within the range of UNICODE character code from ' ' to '?'.
protected static java.lang.String ZENKAKU_KANA_LIST_KEY
          ApplicationResources Key that fetches full-width character table defined in file.
protected static java.lang.String zenkakuKanaList
          Full-width kana string.
 
Field inherited from class org.apache.struts.validator.FieldChecks
FIELD_TEST_EQUAL, FIELD_TEST_NOTNULL, FIELD_TEST_NULL
 
Constructor Summary
FieldChecksEx()
           
 
Method Summary
protected static org.apache.struts.action.ActionForm getActionForm(javax.servlet.http.HttpServletRequest request)
          Fetch form implementation object.
protected static org.apache.commons.validator.Field getArrayIndexField(org.apache.commons.validator.Field field, int pos)
          Fetch field of specified Index.
protected static int getByteLength(java.lang.String value, java.lang.String encoding)
          Fetch byte length of specified string.
static java.lang.String getHankakuKanaList()
          Fetch list of half-width kana.
protected static java.lang.reflect.Method getMethod(org.apache.commons.validator.ValidatorAction va, java.lang.Class[] paramClass)
          Fetch the method that validates the element of array and collection.
protected static java.lang.Class[] getParamClass(org.apache.commons.validator.ValidatorAction va)
          Fetch the argument class array that is passed to validation rule method.
static java.lang.String getZenkakuKanaList()
          Fetch the list of full-width kana.
protected static boolean isHankaku(char c)
          Check if the specified character is half-width character.
protected static boolean isHankakuKana(char c)
          Check if the specified character is half-width kana character.
protected static boolean isValid(java.lang.Object result)
          Check if the validation has been successful or not from the result object of the method which was executed by using reflection.
protected static boolean isZenkaku(char c)
          Check if the specified character is full-width character.
protected static boolean isZenkakuKana(char c)
          Check if the specified character is the full-width kana character.
protected static java.lang.String replaceIndexString(java.lang.String arg, int pos)
          When the value of arg is ##INDEX, replace it with index value which is under scanning. Since this method is for action form, it is not recommended to use it for any class other than form.
static boolean validateAlphaNumericString(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the specified field is alphanumeric character.
static boolean validateArraysIndex(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check all the elements for the field value of array and collection type.
static boolean validateByteLength(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the byte length of specified field matches.
static boolean validateByteRange(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the byte length of specified field is within the specified range.
static boolean validateCapAlphaNumericString(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the specified field is uppercase alphanumeric character.
static boolean validateDateRange(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the date is within the specified range.
static boolean validateHankakuKanaString(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the specified field is half-width kana string.
static boolean validateHankakuString(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the specified field is half-width string.
static boolean validateMultiField(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check the correlation of multiple fields.
static boolean validateNumber(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the specified field is numeric value.
static boolean validateNumericString(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the specified field is the string that contains only numeric characters.
static boolean validateProhibited(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the specified field contains the input prohibited characters.
static boolean validateStringLength(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the string length of specified field matches.
static boolean validateZenkakuKanaString(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the specified field is full-width katakana string.
static boolean validateZenkakuString(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
          Check if the specified field is the full-width string.
 
MEthod inherited from class org.apache.struts.validator.FieldChecks
isString, validateByte, validateCreditCard, validateDate, validateDouble, validateDoubleRange, validateEmail, validateFloat, validateFloatRange, validateInteger, validateIntRange, validateLong, validateMask, validateMaxLength, validateMinLength, validateRequired, validateRequiredIf, validateShort, validateUrl
 
Method inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Details

serialVersionUID

private static final long SerialVersion UID
Serial version ID

See Also:
Constant field value

log

private static org.apache.commons.logging.Log log
Log class.


INDEX

public static final java.lang.String INDEX
Index value of the array index type field.

See Also:
Constant field value

hankakuKanaList

protected static java.lang.String hankakuKanaList
It is half-width kana string. Define in ApplicationResources file.


zenkakuKanaList

protected static java.lang.String zenkakuKanaList
It is full-width kana string. Define in ApplicationResources file.


HANKAKU_KANA_LIST_KEY

protected static final java.lang.String HANKAKU_KANA_LIST_KEY
Key that fetches half-width character table defined in ApplicationResources file.

See Also:
Constant field value

ZENKAKU_KANA_LIST_KEY

protected static final java.lang.String ZENKAKU_KANA_LIST_KEY
Key that fetches full-width character table defined in ApplicationResources file.

See Also:
Constant field value

ZENKAKU_BEGIN_U00_LIST

protected static final java.lang.String ZENKAKU_BEGIN_U00_LIST
Full-width string that exists within the range of UNICODE character code from ' ' to '?'.

See Also:
Constant field value
Constructor Details

FieldChecksEx

public FieldChecksEx()
Method Details

isHankakuKana

protected static boolean isHankakuKana(char c)
Check if the specified character is half-width kana character.

Parameter:
c - Character
Returns:
true if it is half-width kana character

isHankaku

protected static boolean isHankaku(char c)
Check if the specified character is half-width character.

Parameter:
c - Character
Returns:
true if it is half-width character

isZenkaku

protected static boolean isZenkaku(char c)
Check if specified character is full-width character.

Parameter:
c - Character
Returns:
true if it is full-width character

isZenkakuKana

protected static boolean isZenkakuKana(char c)
Check if the specified character is full-width kana character.

Parameter:
c - Character
Returns:
true if it is full-width kana character

validateAlphaNumericString

public static boolean validateAlphaNumericString(java.lang.Object bean,
                                                 org.apache.commons.validator.ValidatorAction va,
                                                 org.apache.commons.validator.Field field,
                                                 org.apache.struts.action.ActionMessages errors,
                                                 org.apache.commons.validator.Validator validator,
                                                 javax.servlet.http.HttpServletRequest request)
Check if the specified field is alphanumeric character.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml.

Parameter:
bean - Object to be checked
va - ValidatorAction prepared by Struts
field - Field object
errors - ActionMessages action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateCapAlphaNumericString

public static boolean validateCapAlphaNumericString(java.lang.Object bean,
                                                    org.apache.commons.validator.ValidatorAction va,
                                                    org.apache.commons.validator.Field field,
                                                    org.apache.struts.action.ActionMessages errors,
                                                    org.apache.commons.validator.Validator validator,
                                                    javax.servlet.http.HttpServletRequest request)
Check if the specified field is uppercase alphanumeric character.

When error occurs, generate error information and add it into the specified error information list.Describe the format of error messages in validation-rules.xml.

Parameter:
bean - Object to be checked
va - ValidatorAction prepared by Struts
field - Field object
errors - ActionMessages action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateNumber

public static boolean validateNumber(java.lang.Object bean,
                                     org.apache.commons.validator.ValidatorAction va,
                                     org.apache.commons.validator.Field field,
                                     org.apache.struts.action.ActionMessages errors,
                                     org.apache.commons.validator.Validator validator,
                                     javax.servlet.http.HttpServletRequest request)
Check if the specified field is the numeric value. First, generate BigDecimal type by using entered string. When it is not possible to generate it then create ActionMessage for error and return false. When the length of the integer part is specified, check the length. Identical check is performed for number of integers only when isAccordedInteger() is specified as "true" in validation.xml. When the check fails, create ActionMessage for errors and return false. In the end, check the length of the fractional part, if specified. Identical check is performed for number of fractions only when isAccordedScale is specified as "true" in validation.xml.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml.
Following is an example of validating the numeric value having 3 integer parts and 2 fractional parts.

Description example of validation.xml
 <form name="/sample">
  ...
  <field property="escape"
      depends="number">
    <arg0 key="sample.escape"/>
    <var>
      <var-name>integerLength</var-name>
      <var-value>3</var-value>
    </var>
    <var>
      <var-name>scale</var-name>
      <var-value>2</var-value>
    </var>
    <var>
      <var-name>isAccordedInteger</var-name>
      <var-value>true</var-value>
    </var>
    <var>
      <var-name>isAccordedScale</var-name>
      <var-value>true</var-value>
    </var>
  </field>
  ...
 </form>
 
<var> element that need to be set in validation.xml
var-name
var-value
Required
Overview
integerLength Length of integer part false When isAccordedInteger that sets the length of integer, is not specified, check if the value is within the specified number. When not specified or nonnumeric value is set, do not perform validation.
scale Length of fractional part false When isAccordedScale that sets length of fractional value, is not specified, check if the value is within the specified number. When not specified or non-numeric value is set, do not perform validation.
isAccordedInteger Equality check for length of integers false When true is specified, equality check is performed for length of integers. When not specified or the string other than true is set, check if the value is within the specified number.
isAccordedScale Equality check for length of fractions false When true is specified, equality check is performed for length of fractions. When not specified or the string other than true is set, check if the value is within the specified number.

Parameter:
bean - Object to be checked
va - ValidatorAction prepared by Struts
field - Field object
errors - ActionMessages action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateHankakuKanaString

public static boolean validateHankakuKanaString(java.lang.Object bean,
                                                org.apache.commons.validator.ValidatorAction va,
                                                org.apache.commons.validator.Field field,
                                                org.apache.struts.action.ActionMessages errors,
                                                org.apache.commons.validator.Validator validator,
                                                javax.servlet.http.HttpServletRequest request)
Check if the specified field is half-width kana string.

When error occurs, generate error information and add it into the specified error information list.Describe the format of error messages in validation-rules.xml.

Parameter:
bean - Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - ActionMessages action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateHankakuString

public static boolean validateHankakuString(java.lang.Object bean,
                                            org.apache.commons.validator.ValidatorAction va,
                                            org.apache.commons.validator.Field field,
                                            org.apache.struts.action.ActionMessages errors,
                                            org.apache.commons.validator.Validator validator,
                                            javax.servlet.http.HttpServletRequest request)
Check if the specified field is half-width string.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml.

Parameter:
bean - Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateZenkakuString

public static boolean validateZenkakuString(java.lang.Object bean,
                                            org.apache.commons.validator.ValidatorAction va,
                                            org.apache.commons.validator.Field field,
                                            org.apache.struts.action.ActionMessages errors,
                                            org.apache.commons.validator.Validator validator,
                                            javax.servlet.http.HttpServletRequest request)
Check if the specified field is full-width string.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml.

Parameter:
bean - Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateZenkakuKanaString

public static boolean validateZenkakuKanaString(java.lang.Object bean,
                                                org.apache.commons.validator.ValidatorAction va,
                                                org.apache.commons.validator.Field field,
                                                org.apache.struts.action.ActionMessages errors,
                                                org.apache.commons.validator.Validator validator,
                                                javax.servlet.http.HttpServletRequest request)
Check if the specified field is a full-width katakana string.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml.

Parameter:
bean - Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateProhibited

public static boolean validateProhibited(java.lang.Object bean,
                                         org.apache.commons.validator.ValidatorAction va,
                                         org.apache.commons.validator.Field field,
                                         org.apache.struts.action.ActionMessages errors,
                                         org.apache.commons.validator.Validator validator,
                                         javax.servlet.http.HttpServletRequest request)
Check if the specified field contains input prohibited string.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml.
Following is an example of prohibited string check settings.

Description example of validation.xml
 <form name="/sample">
  ...
  <field property="escape"
      depends="prohibited">
    <arg0 key="sample.escape"/>
    <var>
      <var-name>chars</var-name>
      <var-value>!"#$%&'()</var-value>
    </var>
  </field>
  ...
 </form>
 
<var> element that need to be set in validation.xml
var-name
var-value
Required
Overview
chars Input prohibited characters false Return false when the input characters corresponds to any of the input prohibited characters. When not specified, true

Parameter:
bean -Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateNumericString

public static boolean validateNumericString(java.lang.Object bean,
                                            org.apache.commons.validator.ValidatorAction va,
                                            org.apache.commons.validator.Field field,
                                            org.apache.struts.action.ActionMessages errors,
                                            org.apache.commons.validator.Validator validator,
                                            javax.servlet.http.HttpServletRequest request)
Check if the specified field is the characters string that consists of only numeric characters.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml.

Parameter:
bean -Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateStringLength

public static boolean validateStringLength(java.lang.Object bean,
                                           org.apache.commons.validator.ValidatorAction va,
                                           org.apache.commons.validator.Field field,
                                           org.apache.struts.action.ActionMessages errors,
                                           org.apache.commons.validator.Validator validator,
                                           javax.servlet.http.HttpServletRequest request)
Check if the string length of specified field matches.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml.
Following is a configuration example of validation where true is returned only when the string length is 5.

Description example of validation.xml
 <form name="/sample">
  ...
  <field property="escape"
      depends="stringLength">
    <arg0 key="sample.escape"/>
    <var>
      <var-name>length</var-name>
      <var-value>5</var-value>
    </var>
  </field>
  ...
 </form>
 
<var> element that need to be set in validation.xml
var-name
var-value
Required
Overview
stringLength Input string length false true is returned when the length of input string is as per the specified length. When not specified, true is returned.

Parameter:
bean -Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateByteLength

public static boolean validateByteLength(java.lang.Object bean,
                                         org.apache.commons.validator.ValidatorAction va,
                                         org.apache.commons.validator.Field field,
                                         org.apache.struts.action.ActionMessages errors,
                                         org.apache.commons.validator.Validator validator,
                                         javax.servlet.http.HttpServletRequest request)
Check if the byte length of specified field matches.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml.
Following is a configuration example of validation where true is returned only when the byte length is 5.

Description example of validation.xml
 <form name="/sample">
  ...
  <field property="escape"
      depends="byteLength">
    <arg0 key="sample.escape"/>
    <var>
      <var-name>byteLength</var-name>
      <var-value>5</var-value>
    </var>
    <var>
      <var-name>encoding</var-name>
      <var-value>Windows-31J</var-value>
    </var>
  </field>
  ...
 </form>
 
lt;var> element that need to be set in validation.xml
var-name
var-value
Required
Overview
byteLength Input string byte length false Validating the byte length of input string.
encoding Character encoding false Character encoding used while converting the input characters into byte array.When omitted, default encoding of VM is used.

Parameter:
bean -Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateByteRange

public static boolean validateByteRange(java.lang.Object bean,
                                        org.apache.commons.validator.ValidatorAction va,
                                        org.apache.commons.validator.Field field,
                                        org.apache.struts.action.ActionMessages errors,
                                        org.apache.commons.validator.Validator validator,
                                        javax.servlet.http.HttpServletRequest request)
Check if the byte length of specified field is within the specified range.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error messages in validation-rules.xml Following is a configuration example of validation where true is returned only when the byte length is greater than 5 and less than 10.

Description example of validation.xml
 <form name="/sample">
  ...
  <field property="escape"
      depends="byteRange">
    <arg0 key="sample.escape"/>
    <var>
      <var-name>maxByte</var-name>
      <var-value>10</var-value>
    </var>
    <var>
      <var-name>minByte</var-name>
      <var-value>5</var-value>
    </var>
    <var>
      <var-name>encoding</var-name>
      <var-value>Windows-31J</var-value>
    </var>
  </field>
  ...
 </form>
 
<var> element that need to be set in validation.xml
var-name
var-value
Required
Overview
maxByte Maximum bytes false Maximum byte length for validating the byte length of input string.When omitted, maximum value of int type.
minByte Minimum bytes false Minimum byte length for validating the byte length of input string. 0 when omitted.
encoding Character encoding false Character encoding used while converting the input characters into byte array.When omitted, default encoding of VM is used.

Parameter:
bean -Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateDateRange

public static boolean validateDateRange(java.lang.Object bean,
                                        org.apache.commons.validator.ValidatorAction va,
                                        org.apache.commons.validator.Field field,
                                        org.apache.struts.action.ActionMessages errors,
                                        org.apache.commons.validator.Validator validator,
                                        javax.servlet.http.HttpServletRequest request)
Check if the date is within the specified range.

When error occurs, generate error information and add it into the specified error information list. Describe the format of error message in validation-rules.xml.
Following is an configuration example where it is validated that the date within the range of 2000/01/01 to 2010/12/31.

Description example of validation.xml
 <form name="/sample">
  ...
  <field property="date"
      depends="dateRange">
    <arg key="label.date" position="0"/>
    <var>
      <var-name>startDate</var-name>
      <var-value>2000/01/01</var-value>
    </var>
    <var>
      <var-name>endDate</var-name>
      <var-value>2010/12/31</var-value>
    </var>
    <var>
      <var-name>datePattern</var-name>
      <var-value>yyyy/MM/dd</var-value>
    </var>
  </field>
  ...
 </form>
 
<var> element that need to be set in validation.xml
var-name
var-value
Required
Overview
startDate Start date false Date which is the start threshold value of date range. It should match with the data format specified in datePattern or datePatternStrict.
endDate End date false Date which is the end threshold value of date range. It should match with the data format specified in datePattern or datePatternStrict.
datePattern Date pattern false String that indicates date pattern. Follow the format rules of Date type.
datePatternStrict String that indicates date pattern.Follow the format rules of Date type. false Indicates whether strict date pattern check is to be performed. When date pattern is yyyy/MM/dd, 2001/1/1 is erroneous. When datePattern is specified, priority is given to the format specified in datePattern.

Parameter:
bean -Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateMultiField

public static boolean validateMultiField(java.lang.Object bean,
                                         org.apache.commons.validator.ValidatorAction va,
                                         org.apache.commons.validator.Field field,
                                         org.apache.struts.action.ActionMessages errors,
                                         org.apache.commons.validator.Validator validator,
                                         javax.servlet.http.HttpServletRequest request)
Perform correlation check for multiple fields. Implementation class of MultiFieldValidator is necessary for executing these validation rules. Perform the settings of implementation class in validation.xml.
When error occurs, generate error information and add it into the specified error information list. Since these validation rules does not contain any default error messages, messages should always be described in validation.xml.
Perform the implementation and settings as follows at the time of validating if the value of value field of action form is greater than value of value1 field and less than the value of value2 field.
Implementation example of MultiFieldValidator
 public boolean validate(String value, String[] depends) {
  int value0 = Integer.parseInt(value);
  int value1 = Integer.parseInt(depends[0]);
  int value2 = Integer.parseInt(depends[1]);
  return (value1 <= value0 && value2 >= value0);
 }
 
Configuration example of validation.xml
 <form name="/validateMultiField">
   <field property="value" depends="multiField">
     <msg key="errors.multiField"
             name="multiField"/>
     <arg key="label.value" position="0" />
     <arg key="label.value1" position="1" />
     <arg key="label.value2" position="2" />
     <var>
       <var-name>fields</var-name>
       <var-value>value1,value2</var-value>
     </var>
     <var>
       <var-name>multiFieldValidator</var-name>
       <var-value>sample.SampleMultiFieldValidator</var-value>
     </var>
   </field>
 </form>
 
Configuration example of message resource file
In errors.multiField={0}, enter the value which is between {1} to {2}.
<var> element that need to be set in validation.xml
var-name
var-value
Required
Overview
fields Other field names necessary for validation false While specifying multiple fields, specify the field names with comma separator.
multiFieldValidator MultiFieldValidator implementation class name false MultiFieldValidator implementation class name that performs correlation check for multiple fields.

Parameter:
bean -Object to be checked
va - ValidatorAction prepared by Validator
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value is correct

validateArraysIndex

public static boolean validateArraysIndex(java.lang.Object bean,
                                          org.apache.commons.validator.ValidatorAction va,
                                          org.apache.commons.validator.Field field,
                                          org.apache.struts.action.ActionMessages errors,
                                          org.apache.commons.validator.Validator validator,
                                          javax.servlet.http.HttpServletRequest request)
Perform all elements check for the field values of array and collection type.

Validate all array and collection type elements of form and add the generated index information in ActionMessage. argument type and sequence of executed submethod should match with this method. Nested property name can be set in the "property" attribute of Field as per the JXPathIndexedBeanWrapperImpl specifications.

Parameter:
bean -Object to be checked
va - ValidatorAction prepared by Struts
field - Field object
errors - action error
validator - Validator instance
request - HTTP request
Returns:
true when input value of all elements is correct

getActionForm

protected static org.apache.struts.action.ActionForm getActionForm(javax.servlet.http.HttpServletRequest request)
Fetch form implementation object. Since this method is for action form, it is not recommended to use it for any class other than form.

Parameter:
request - HTTP request
Returns:
Form implementation object

getParamClass

protected static java.lang.Class[] getParamClass(org.apache.commons.validator.ValidatorAction va)
Fetch argument class array which is passed to validation rule method. Since this method is for action form, it is not recommended to use it for any class other than form.

Parameter:
va - ValidatorAction prepared by Struts
Returns:
Argument class array

getMethod

protected static java.lang.reflect.Method getMethod(org.apache.commons.validator.ValidatorAction va,
                                                    java.lang.Class[] paramClass)
Fetch the method that validates element of array and collection. Since this method is for action form, it is not recommended to use it for any class other than form.

Parameter:
va - ValidatorAction prepared by Struts
paramClass - Argument class array
Returns:
Validation method object

isValid

protected static boolean isValid(java.lang.Object result)
Check if the validation has been successful or not from the result object of the method which was executed by using reflection. Since this method is for action form, it is not recommended to use it for any class other than form.

Parameter:
result - Result object
Returns:
true when validation is successful

getArrayIndexField

protected static org.apache.commons.validator.Field getArrayIndexField(org.apache.commons.validator.Field field,
                                                                       int pos)
Fecth the field of specified Index. Since this method is for action form, it is not recommended to use it for any class other than form.

Parameter:
field - Replacement source field object
pos - Index under scanning
Returns:
Field object of replacement destination

replaceIndexString

protected static java.lang.String replaceIndexString(java.lang.String arg,
                                                     int pos)
When the value of arg is ##INDEX, replace it with index value which is under scanning. Since this method is for action form, it is not recommended to use it for any class other than form.

Parameter:
arg - Replacement source key information of ActionMessage
pos - Index under scanning
Returns:
When key is ##INDEX, return the current index

getByteLength

protected static int getByteLength(java.lang.String value,
                                   java.lang.String encoding)
Fetch the byte length of specified string.
Converted into byte array using the encoding specified as second parameter. However, if encoding is not specified or conversion to the specified encoding fails, default encoding is used to convert to byte array.

Parameter:
value - Target string that fetches byte length
encoding - Character encoding
Returns:
Byte length

getHankakuKanaList

public static java.lang.String getHankakuKanaList()
Fetch the list of half-width kana.

Returns:
Half-width kana list

getZenkakuKanaList

public static java.lang.String getZenkakuKanaList()
Fetch list of full-width kana.

Returns:
Full-width kana list