|
||||||||||
Previous class Subsequent class | Frames No frames | |||||||||
Overview: Nested | Field | Constructor | Method | Details: Field | Constructor | Method |
java.lang.Objectorg.apache.struts.validator.FieldChecks
jp.terasoluna.fw.web.struts.form.FieldChecksEx
public class FieldChecksEx
Validator
Additional rule class.
Input check class wherein FieldChecks
provided by Struts
is extended.
Following are the extension rules of FieldChecksEx
.
Alphanumeric character check | validateAlphaNumericString() |
alphaNumericString |
Check if field value consists of only half-width alphanumeric characters. | |
Uppercase alphanumeric character check | validateCapAlphaNumericString() |
capAlphaNumericString |
Check if value consists of only uppercase half-width alphanumeric characters. | |
Field numeric value check | validateNumber() |
number |
Check if field value is the numeric value. | |
Half-width kana character check | validateHankakuKanaString() |
hankakuKanaString |
Check if field value consists of only half-width kana. | |
Half-width character check | validateHankakuString() |
hankakuString |
Check if field value consists of only half-width characters. | |
Full-width character check | validateZenkakuString() |
zenkakuString |
Check if field value consists of only full-width characters. | |
Full-width kana character check | validateZenkakuKanaString() |
zenkakuKanaString |
Check if field value consists of only full-width kana characters. | |
Input prohibited character check | validateProhibited() |
prohibited |
Check if field value does not include input prohibited characters. | |
String length match check | validateStringLength() |
stringLength |
Check if the field value matches with the specified string length. | |
Numeric string check | validateNumericString() |
numericString |
Check if field value consists of only numeric characters. | |
Byte length check | validateByteLength() |
byteLength |
Check if byte length of field value matches with the specified length. | |
Byte range check | validateByteRange() |
byteRange |
Check if the byte length of field value is within the specified range. | |
Date range check | validateDateRange() |
dateRange |
Check if the date of field value is within the specified range. | |
Multiple field check | validateMultiField() |
multiField |
Check the correlation between multiple fields. | |
Array/collection type field all elements check | 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.
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.)
<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>
Following points are extended in the list validation of array and collection type.
<form>
element is created in validation.xml
.
However, following settings are necessary to perform list validation of array and collection type.
property
attribute.
. In property name, it is possible to specify the nested property name according to the JXPathIndexedBeanWrapperImpl specifications.<depends>
must use the rule names in validation-rules.xml
with Array
in the end. requiredArray
minLengthArray
maxLengthArray
maskArray
byteArray
shortArray
integerArray
longArray
floatArray
doubleArray
dateArray
intRangeArray
doubleRangeArray
floatRangeArray
creditCardArray
emailArray
urlArray
alphaNumericStringArray
hankakuKanaStringArray
hankakuStringArray
zenkakuStringArray
zenkakuKanaStringArray
capAlphaNumericStringArray
numberArray
numericStringArray
prohibitedArray
stringLengthArray
dateRangeArray
byteLengthArray
byteRangeArray
<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
FormEx
,
DynaValidatorActionFormEx
,
ValidatorActionFormEx
,
JXPathIndexedBeanWrapperImpl
,
Serialized formField Summary | |
---|---|
protected static java.lang.String |
HANKAKU_KANA_LIST_KEY
Key that fetches the half-width character table defined in ApplicationResources file. |
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 |
---|
private static final long SerialVersion UID
private static org.apache.commons.logging.Log log
public static final java.lang.String INDEX
protected static java.lang.String hankakuKanaList
ApplicationResources
file.
protected static java.lang.String zenkakuKanaList
ApplicationResources
file.
protected static final java.lang.String HANKAKU_KANA_LIST_KEY
ApplicationResources
file.
protected static final java.lang.String ZENKAKU_KANA_LIST_KEY
ApplicationResources
file.
protected static final java.lang.String ZENKAKU_BEGIN_U00_LIST
Constructor Details |
---|
public FieldChecksEx()
Method Details |
---|
protected static boolean isHankakuKana(char c)
c
- Character
true
if it is half-width kana characterprotected static boolean isHankaku(char c)
c
- Character
true
if it is half-width characterprotected static boolean isZenkaku(char c)
c
- Character
true
if it is full-width characterprotected static boolean isZenkakuKana(char c)
c
- Character
true
if it is full-width kana characterpublic 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)
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
.
bean
- Object to be checkedva
- ValidatorAction prepared by Strutsfield
- Field objecterrors
- ActionMessages action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correct 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)
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
.
bean
- Object to be checkedva
- ValidatorAction prepared by Struts field
- Field object errors
- ActionMessages action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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.
<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-name |
var-value |
||
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. |
bean
- Object to be checkedva
- ValidatorAction prepared by Struts field
- Field object errors
- ActionMessages action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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
.
bean
- Object to be checkedva
- ValidatorAction
prepared by Validator
field
- Field object errors
- ActionMessages action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correct 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)
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
.
bean
- Object to be checked va
- ValidatorAction
prepared by Validator
field
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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
.
bean
- Object to be checked va
- ValidatorAction
prepared by Validator
field
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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
.
bean
- Object to be checked va
- ValidatorAction
prepared by Validator
field
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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.
<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-name |
var-value |
||
chars | Input prohibited characters | false | Return false when the input characters corresponds to any of the input prohibited characters. When not specified, true |
bean
-Object to be checkedva
- ValidatorAction
prepared by Validator
field
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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
.
bean
-Object to be checkedva
- ValidatorAction
prepared by Validator
field
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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.
<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-name |
var-value |
||
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. |
bean
-Object to be checkedva
- ValidatorAction prepared by Validatorfield
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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.
<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>
var-name |
var-value |
||
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. |
bean
-Object to be checkedva
- ValidatorAction prepared by Validatorfield
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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.
<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-name |
var-value |
||
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. |
bean
-Object to be checkedva
- ValidatorAction prepared by Validatorfield
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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.
<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-name |
var-value |
||
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. |
bean
-Object to be checkedva
- ValidatorAction prepared by Validatorfield
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
MultiFieldValidator
is necessary for executing these validation rules.
Perform the settings of implementation class in validation.xml
.validation.xml
. 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);
}
<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>
In errors.multiField={0}, enter the value which is between {1} to {2}.
var-name |
var-value |
||
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. |
bean
-Object to be checkedva
- ValidatorAction prepared by Validatorfield
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value is correctpublic 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)
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.
bean
-Object to be checkedva
- ValidatorAction
prepared by Strutsfield
- Field object errors
- action errorvalidator
- Validator instancerequest
- HTTP request
true
when input value of all elements is correctprotected static org.apache.struts.action.ActionForm getActionForm(javax.servlet.http.HttpServletRequest request)
request
- HTTP request
protected static java.lang.Class[] getParamClass(org.apache.commons.validator.ValidatorAction va)
va
- ValidatorAction
prepared by Struts
protected static java.lang.reflect.Method getMethod(org.apache.commons.validator.ValidatorAction va, java.lang.Class[] paramClass)
va
- ValidatorAction
prepared by StrutsparamClass
- Argument class array
protected static boolean isValid(java.lang.Object result)
result
- Result object
true
when validation is successfulprotected static org.apache.commons.validator.Field getArrayIndexField(org.apache.commons.validator.Field field, int pos)
field
- Replacement source field objectpos
- Index under scanning
protected static java.lang.String replaceIndexString(java.lang.String arg, int pos)
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.
arg
- Replacement source key information of ActionMessage
pos
- Index under scanning
protected static int getByteLength(java.lang.String value, java.lang.String encoding)
value
- Target string that fetches byte lengthencoding
- Character encoding
public static java.lang.String getHankakuKanaList()
public static java.lang.String getZenkakuKanaList()
|
||||||||||
Previous class Subsequent class | Frames No frames | |||||||||
Overview: Nested | Field | Constructor | Method | Details: Field | Constructor | Method |