jp.terasoluna.fw.web.struts.form
Interface MultiFieldValidator


public interface MultiFieldValidator

Interface that performs the correlation input check of multiple fields. To execute the input check as per the dependency relationship between multiple fields of action form in the presentation layer, create the class in which this interface is implemented. In validate(String, String[]) method, the first argument is the value to be validated and second argument is the value of dependent field passed as an array. Returns false when there is a validation error.
Please note that field to be validated can be passed as null or blank character. Since there is no default error message for this validation rule, message should always be set in validation.xml.
*This validation rule does not support JavaScript check.

At the time of validating if the value in value field of action form is greater than the value in value1 field and less than the value in value2 field, perform the implementation and settings as follows.

Implementation example of MultiFieldValidator
 public boolean validate(String value, String[] fields) {
     int value0 = Integer.parseInt(value);
     int value1 = Integer.parseInt(fields[0]);
     int value2 = Integer.parseInt(fields[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}.


Method Summary
 boolean validate(java.lang.String value, java.lang.String[] fields)
          Executes correlation input check of multiple fields.
The value to be validated is passed as the first argument. Value of other fields required for the validation is passed as array element in the second argument. Returns false when there is a validation error.
 

Method Detail

validate

boolean validate(java.lang.String value,
                 java.lang.String[] fields)
Executes correlation input check of multiple fields.
The value to be validated is passed as the first argument. Value of other fields required for the validation is passed as array element in the second argument. Returns false when there is validation error.

Parameters:
value - Value to be validated
fields - Array element of other fields required for validation
Returns:
true
when there is no error.