This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 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
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
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: me urgent !!!!
Similar Threads
I heard that I can apply for SCEA without passing SCJP or SCJD first
Web services through jax rpc or soap which is better solution
K & B second mock exam
I want to use xmlhttp in my JSP page
Using c:if ,logic:empty to check existence of bean data