(VALILDATE) VALIDATE Create FORMBEAN

xiaoxiao2021-03-06  96

Under Validate, Struts offers three formBean forms. (1) Create a specific Form Bean object:

Package com.jamesholmes.minihr;

Import org.apache.struts.validator

.Validatorform;

Public class logonform extends validatorform {

PRIVATE STRING UserName;

PRIVATE STRING Password;

Public string getUsername () {

Return UserName;

}

Public void setusername (String

Username) {

THIS.USERNAME = UserName;

}

Public string getpassword () {

Return Password;

}

Public void setpassword (String

Password) {

this.password = password;

}

}

This class is similar to you not using the class created by Validator, but it provides ValidatorForm instead of an actionform. This class does not provide an implementation process for ActionForm's empty reset () and validate () methods because ValidatorForm provides the corresponding process. The method of configuring this specific form bean in the struts-config.xml file is the same as the configured regular form bean:

TYPE = "com.jamesholmes

.minihr.logonform "/>

The logical name specified by the form marked to a specific FORM bean is the name used when defining the validation in the validation.xml file, as shown below:

PUBLIC "- // Apache Software Foundation //

DTD Commons Validator Rules

Configuration 1.0 // en "

"http://jakarta.apache.org/

Commons / DTDS / Validator_1_0.dtd ">>

Depends = "Required">

Validator uses the value of the Name property of the form mark to match the name of the authentication definition with the name of the defined Form bean to apply. (2) Create a dynamic Form Bean object:

TYPE = "Org.apache

. Struts.validator.Dynavalidatorform ">

TYPE = "java.lang.string" />

TYPE = "java.lang.string" />

Dynamic Form Bean does not require a specific Form Bean object; the opposite, to define the properties and types of the Form Bean, and Struts creates a Form Bean dynamically. Validator allows you to use this concept, just like this concept in core Struts. The only difference between using Validator is to specify that form bean is org.apache.struts.validator.dyNavalidatorForm type, not org.apache.struts.Action.DynaActionform type. The logical name assigned to the dynamic Form bean is the name used when defining the validation in the validation.xml file. Validator uses the names that match the name to the Form Bean. (3) Create a advanced Form Bean object: link multiple authentication definitions with a Form Bean definition. When you use ValidatorForm or DynavalidatorForm's Form Bean, Validator uses the logical name of the Form Bean in the struts-config.xml file, map the FORM BEAN to the validation definition in the validation.xml file. Validator provides two additional ActionForm subclasses that allow you to associate validation and operations instead of being associated with the Form Bean. This way you can use the form bean to specify which verification is used for the form bean. For specific Form Beans, you have to declare the org.apache.struts.validator.validatorActionform subclass like this: public class addressform extends ValidatorActionform {

...

}

For dynamic Form Beans, specify the type of Org.apache.Struts.validator.DynavalidatorActionForm for the Form.Apache.Struts.valiDator.Dynavalidator, in the struts-config.xml file, as follows:

Type = "org.apache.struts

.validator.dynavalidatorActionform ">>

...

In the validation.xml file, map a set of verifications to an action path instead of being mapped to the Form Bean name, because if you define the Create Address and Edit Address two operations (they use the same form bean), then each There will be a unique operation name as follows:

TYPE = "com.jamesholmes

.minihr.createaddressaction "

Name = "addressform" />

TYPE = "com.jamesholmes

.minihr.editaddressAction "name =" addressform "/>

The following Validation.xml file is displayed two sets of verification, which are used for the same form bean, but there are different operating paths:

Depends = "Required">

Depends = "Required">

Because the Form bean either belongs to the ValidatorActionform subclass, you or if you belong to the DynavalidatorActionform subclass, Validator knows that the logical name of the Form Bean is found in the logical name of the Form Bean with an operation path.

转载请注明原文地址:https://www.9cbs.com/read-106703.html

New Post(0)