Validator verification framework
The validator framework can overcome the limitations of programming data verification in actionform bean. It allows struts to apply flexible configuration verification rules without programming.
The validator framework mainly depends on two jar files: jakarta-oro.jar and commons-validator,. Jar
The validator framework uses two XML-based configuration files to configure verification rules. The two files are the validator-rules.xml and validation. xml.
Validator-rules.xml files replace a set of common validation rules that apply to all struts applications. In general, there is no need to modify the file unless you need to modify or extend the default rules.
The element has seven attributes:
Name attribute: The name attribute specifies the logic name of the validation rule, which must be unique.
Classname and method attributes: The classname and method attributes specify the classes and methods that implement the logic of verification rules.
Methodparams: attribute is used to specify parameters contained in the verification method. Multiple parameters are separated by commas.
MSG attribute: the MSG attribute specifies the Message key from the resource bundle. When the verification fails, the validator framework searches for the matched message text in the resource bundle Based on the Message key.
Depends attribute: The depends attribute specifies other verification rules that must be called before the current verification rule is called.
The validator framework provides basic and common verification rules, which are applicable to struts applications and non-Struts applications. The Org. Apache. commons. validator. genericvalidator class provides a set of static methods to implement these rules.
Methods for verifying the genericvalidator class:
Isblankornull: Check whether the field is null or the length is 0.
Isbyte: verify whether a field can be converted to a data with a small byte type.
Iscreditcard: whether the verification field is a valid credit card number.
Isdate: verify whether the field is a valid date.
Isdouble: verify whether the field can be converted to a valid double type data.
Isemail: verify whether the field is a valid email address.
Isfloat: verify whether a field can be converted to a valid float type data.
Isinrange: used between the minimum and maximum values when the yundun millet is disconnected.
Isint: checks whether a field can be converted to a valid int type data.
Islong: checks whether a field can be converted to a valid long data type.
Isshort: verify whether a field can be converted to a valid short type data.
Matchtegexp: Verify that the field matches the regular expression.
Maxlength: When verifying a field, it is less than or equal to the maximum value.
Minlength: When verifying a field, it must be greater than or equal to the minimum value.
The Org. Apache. Struts. validator. fieldchecks class specifically used to verify form fields is defined in the Struts framework. It provides methods similar to genericvalidator. The following are the verification methods included in the fieldchecks class:
Validatebyte
Validatecreditcard
Validatedate
Validatedouble
Validateemail
Validatefloat
Validateinteger
Validatelong
Validatemask
Validateminlength
Validatemaxlength
Validaterange
Validaterequired
Validateshort
Validation. xml file:
This file is for a specific struts application and needs to be created by developers. It can configure the required verification rules for the actionform in the application, the verification logic is implemented programmatically in the actionform class instead.
The validator framework cannot be used to verify the standard org. Apache. Struts. Action. actionform class. If you want to use the validator framework, use the two subclasses of the actionform class: dynavalidatorform and validatorform.
The validator framework can be used for browser client verification. To perform client verification, you need to use the struts tag, which can generate a javascript tutorial for client verification on the JSP page.