Struts Validation Frame Try 2

zhaozj2021-02-16  56

JavaScript support

In web applications, there are many opportunities to use JavaScript. Although many books mentioning that customers may have the implementation of JS from the browser, don't use it completely, it seems that it doesn't seem to be. For example, some complex UIs must be implemented by JS (such as pull-down menus, etc.). So what is the JS authentication of the Validation framework not supported?

The answer is: Of course. The specific approach is:

- Add οnsubmit = "Return ValidateEditform (this) in the page HTML: Form Tag; (specific syntax: Validate defined in the validation.xml file);

>>>>>>>>

- Add:

So 2 steps. Although the Validation framework is very easy to use, it still needs attention.

Use attention

1. After using the Validation framework, Form must derive from the ValidatorForm, and must first call the validate method of the base class in your validate method. For methods that start with Dyna to create a FORMBEAN reader, you must also change the FORM with Validator with DYNA.

2. Note DynaValidatorForm (ValidatorForm) and DynavalidatorActionform (ValidatorActionform). At the beginning, I didn't understand the difference between these two, and later I obtained the difference from the online article. The main perspective of the former is FORMBEAN, while the latter's perspective is Action.

When FormBean is used by different Action, for different Actions, it is very small for use in the material set of FORMBEAN. At this point, if you still use the FORMBEAN as the main body, it will cause abnormal use of other Actions. Therefore, the Struts proposed DynavalidatorActionform (ValidatorActionform). At this time, the Name property of the FORM tag in Validation.xml is changed to the path properties of Action, and because there is Attribute and Name attribute in the action, the Validation Framework can get the corresponding FORMBEAN according to this action. example:

Depends = "Required">

Depends = "Required">

3. Team with Dispatchaction. Struts1.1's Dispatchaction makes the relationship of the relevant Action, greatly reduces the number of Actions in the application, but with the inconvenience of using the Validation framework, it cannot be said to be a regret. The reader may think that this situation can be used to solve the solution of Article 2, that is, use DyanValidatorActionForm, and then uses different ActionD's path in the validation.xml file, ie in validation.xml: , . However, this Identification framework does not support this recognition in the current version. A method of bypassing this is that the PATH defined in the struts-config.xml file in the Struts-Config.xml file is set to false in the struts-config.xml file. which is:

Struts-config.xml:

Parameter = "Method" scope = "request" type = "foxgem.struts.userdispatchaction"

Validate = "True">

Parameter = "Method" scope = "request" type = "foxgem.struts.userdispatchaction"

Validate = "false">

Then use 2 methods in the validation.xml file.

Conclude

In general, the Validation framework greatly enhances the development efficiency of page validation, more attractive, these verification methods can be reused by custom Validator. Allow these verification code more concentrated, maintaining maintainability. Of course, as the project is carried out, Validation.xml and Validator-Rules.xml will grow, and this part of the maintenance work is aggravated. At the same time, since it is unable to collaborate with Dispatchaction, a large number of items that use Dispatchaction cannot be used very well. It is recommended to use Dispatchaction and page Verification Very complex and multi-change projects to be verified by the original way and do not use the Validation framework.

For additional details of the Validation framework, see the Struts documentation, and details are not described here.

Reference

n http://raibledesigns.com/wiki/wiki.jsp?page= Subsequent solutions for Dispatchaction and the Validation framework come from this.

n http://otn.racle.com/oramag/oracle/04-jan/o14dev_struts.html Check your form with validator

n http://www-900.ibm.com/developerWorks/cn/java/l-struts1-1/ in-depth Struts 1.1

n http://javaboutique.Internet.com/tutorials/struts11val/tepping through the struts 1.1 Validator

About author

Hulu, Master of Engineering, Xi'an Jiaotong University, is keen on J2EE / .NET technology, is the loyal advocator of OpenSource. At present, Xi'an Software Co., Ltd. is currently created with friends. The company is mainly committed to the development of Java web applications, and many projects have been applied in energy, electricity and transportation industries. You can contact him through James.hu@chinacodeline.com.

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

New Post(0)