wood burning stoves 2.0*
The moose likes Struts and the fly likes plz...help me  urgent !!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "plz...help me  urgent !!!!" Watch "plz...help me  urgent !!!!" New topic
Author

plz...help me urgent !!!!

Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

how to validate fields using validation.xml.
can anyone explain me in detail...?
plz.. give me the sample codes...
Advance Thanx..


Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
Rick Hightower
Author
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
Can you be more specific? How far did you get?
The book Professional Struts by Wrox covers it step by step. I know. I wrote that chapter.
To use the Validator Framework, follow these steps:
1.Add the Validator Plugin to the Struts configuration file.
2.Copy the validator-rules.xml and validation.xml files into WEB-INF (from the blank Struts Web application).
3.Change the ActionForm class (UserRegistrationForm.java) to the subclass ValidatorForm (org.apache.struts.validator.ValidatorForm).
4.Add a form to the form set in the validation.xml file corresponding to the attribute name of the form.
5.Add a field to the form declaration in the validation.xml file corresponding to the userName field.
6.Specify that the userName field correspond to the required, minlength, maxlength rules.
7.Add the error message for the rules to the resource bundle.
8.Specify that the username label be the first argument to the error message.
9.Configure the rules.
10. Specify that the value of the rules' minlength variable be the second argument to the error message if there is a minlength rule violation. Do the same for the maxlength variable and the maxlength rule.
11. Turn on Logging

Step 1 is to add the Validator Plugin to the Struts configuration file. The Validator Framework integrates with Struts via this Plugin, which is responsible for reading the configuration files for the Validator rules. To use the Validator Framework with Struts, you need to add this Plugin after any message resource elements in the Struts configuration file as follows:
<plug-in
className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

Here is an example that validates a user name from a form:

The book Struts in Action also covers the Validator Framework.


Rick Hightower is CTO of Mammatus which focuses on Cloud Computing, EC2, etc. Rick is invovled in Java CDI and Java EE as well. linkedin,twitter,blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: plz...help me urgent !!!!