When is the best time to validate input in Struts

By: Apache Foundation Emailed: 1768 times Printed: 2515 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

This is an excellent question. Let's step back a second and think about a typical mid to large size application. If we start from the back end and work toward the view we have:

1) Database: Most modern databases are going to validate for required fields, duplicate records, security constraints, etc.

2) Business Logic: Here you are going to check for valid data relationships and things that make sense for the particular problem you are triing to solve.

... This is where struts comes into the picture, by now the system should be pretty well bulletproof. What we are going to do is make validation friendlier and informative. Rember it is OK to have duplicate validations...

3) ActionErrors validate(ActionMapping map, HttpServletRequest req) is where you can do your validation and feed back to the view, information required to correct any errors. validate is run after the form has been reset and after the ActionForm properties have been set from corresponding view based input. Also remember you can turn validation off with validate="false" in the action mapping in the struts-config.xml. This is done by returning an ActionErrors collection with messages from your ApplicationResources.properties file.

Here you have access to the request so you can see what kinds of action is being requested to fine tune your validations. The <html:error> tag allows you to dump all errors on your page or a particular error associated with a particular property. The input attribute of the struts-config.xml action allows you to send validation errors to a particular jsp / html / tile page.

4) You can have the system perform low level validations and client side feedback using a ValidatorForm or its derivatives. This will generate javascript and give instant feedback to the user for simple data entry errors. You code your validations in the validator-rules.xml file. A working knowledge of regular expressions is necessary to use this feature effectively.


Struts Home | All Struts Tutorials | Latest Struts Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(2)


1. View Comment

This site providing excellent knowledge about struts application

View Tutorial          By: Bellamkonda at 2009-11-12 02:37:44
2. View Comment

This site is an Excellent Choice for lerners.Thank you very much who put efferts for this site.

View Tutorial          By: Sravanthi at 2011-06-28 06:20:35

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Apache Foundation
When is the best time to validate input in Struts
Chaining actions in Struts
Simple example of using the requiredif Validator rule in Struts
How to prepopulate a form in Struts
Using JavaScript to submit a form in Struts
FAQ: Why are my checkboxes not being set from ON to OFF?
FAQ: Why was reload removed from Struts (since 1.1)?

More Tutorials in Struts
Configuring JDBC DataSources in Struts
Struts Classes
FAQ: Why was reload removed from Struts (since 1.1)?
FAQ: Why are my checkboxes not being set from ON to OFF?
Using JavaScript to submit a form in Struts
How to prepopulate a form in Struts
Simple example of using the requiredif Validator rule in Struts
Chaining actions in Struts
When is the best time to validate input in Struts
What is a Plug-in and how to use Java plug-ins with Struts?
7 Best Practices of Struts
Origin and Architecture of Struts
ActionErrors and ActionError in Struts
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Handling multiple buttons in HTML Form in Struts

More Latest News
Most Viewed Articles (in Struts )
ForwardAction in Struts
Handling multiple buttons in HTML Form in Struts
Configuring JDBC DataSources in Struts
Editing web.xml in a Struts Application
Creating the first application using Struts 2
Struts 1 vs Struts 2
MVC Architecture (Model 2 Architecture)
Installing and configuring Tomcat and Struts
Struts and Tiles - Steps to use Struts and Tiles
Creating Struts Modules
Using Multibox in Struts
Use ImageButtonBean for Image based Form Submits in Struts
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Handling Duplicate Form Submissions in Struts
Guidelines for Struts Application Development
Most Emailed Articles (in Struts)
What is a Model View Controller (MVC) Model?
What is Struts? Which Version of Struts to use?
Is Struts the most popular web application framework for Java?
History of Struts
WebWork 2 is now Apache Struts 2
Configuring JDBC DataSources in Struts
Struts Classes
Downloading and installing Struts
The directories and files of a Struts application
Editing web.xml in a Struts Application
Editing struts-config.xml in a Struts Application
Creating the first application using Struts 2
Struts 1 vs Struts 2
Model 1 Architecture
MVC Architecture (Model 2 Architecture)