File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes me  urgent !!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark " me  urgent !!!!" Watch " me  urgent !!!!" New topic
Author me urgent !!!!

Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1850

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

Krishna Srinivasan
OCAJP 7/8 Exam, 400+ OCPJP Mock Questions
Rick Hightower
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 ( 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:

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
I agree. Here's the link:
subject: me urgent !!!!
jQuery in Action, 3rd edition