Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

Struts Tutorial
Struts Introduction
Struts Controller
Struts Action Class
Struts ActionForm Class
Struts HTML Tags
Struts Validator Framework
Struts ClientSide Address Valiadation
Struts Tiles
Using tiles-defs.xml
Dynamic Action Form
Struts File Upload
Struts Database Connection

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


Understanding The Struts Validator Framework

Previoushome Next




Struts Validator Framework

To validate the form data,Struts Framework provides the functionality.

A D V E R T I S E M E N T
It can be use to validate the data on client side as well as on the server side. Struts Framework can be used to validate the form data on the client browser and emits java scripts.By sub classing your From Bean with the DynaValidatorForm class,server side validation of the form can be accomplished . 

David Winterfeldt developed the Validator framework as third-party add-on to the Struts.Now the Validator framework can be used with or without the Struts and it is a part of Jakarta Commons project .The Validator framework can be used without doing any extra settings and comes integrated with Struts Framework.




Using Validator Framework

To pickup validation rules to be applied to an form,validator uses the XML file. In XML validation requirements are applied to the form and aslo can be defined.In validator framework,we can plug in our own custom validations into Validator.

The Validator Framework uses two XML configuration files called validator-rules.xml and validation.xml. Standard validation routines are defined by the validator-rules.xml and used in validation.xml. To define form specific validations,validation.xml is used.To define the validations applied to a form bean,the validation.xml




Structure of validator-rule.xml

The validation-rules.xmldeclares and assigns the logical names to the validation routines and is provided with Validator Framework. For each validation routine,it also contains client-side javascript code . To perform specific validations,the validation routines are the java methods plugged into the system .

Following table contains the details of the elements in this file:

Element Attributes and Description
form-validation

This is the root node. It contains nested elements for all of the other configuration settings.

global

The validator details specified within this, are global and are accessed by all forms.

validator

The validator element defines what validators objects can be used with the fields referenced by the formset elements.

The attributes are:

  • name: Contains a logical name for the validation routine

  • classname: Name of the Form Bean class that extends the subclass of ActionForm class

  • method: Name of the method of the Form Bean class

  • methodParams: parameters passed to the method

  • msg:Validator uses Struts' Resource Bundle mechanism for externalizing error messages. Instead of having hard-coded error messages in the framework, Validator allows you to specify a key to a message in the ApplicationResources.properties file that should be returned if a validation fails. Each validation routine in the validator-rules.xml file specifies an error message key as value for this attribute.

  • depends: If validation is required, the value here is specified as 'required' for this attribute.

  • jsFunctionName: Name of the javascript function is specified here. 

javascript

Contains the code of the javascript function used for client-side validation. Starting in Struts 1.2.0 the default javascript definitions have been consolidated to commons-validator.  The default can be overridden by supplying a <javascript> element with a CDATA section, just as in struts 1.1.

The Validator plug-in which is also known as validator-rules.xml is supplied with the predefined set of commonly used validation rules such as Required, Minimum Length, Maximum length, Date Validation, Email Address validation and more. If required,this basic set of rules can also be extended with the custom validators .




Structure of validation.xml

This validation.xml configuration file define which validation routines that is used to validate Form Beans and also you can define validation logic for any number of Form Beans in this configuration file . Inside that definition, you specify validations you want to apply to the Form Bean's fields and the definition in this file use the logical names of Form Beans from the struts-config.xml file along with the logical names of validation routines from the validator-rules.xml file to tie the two together.

The following table shows the elements of the validation.xml file
Element Attributes and Description
form-validation This is the root node. It contains nested elements for all of the other configuration settings
global The constant details are specified in <constant> element within this element.
constant Constant properties are specified within this element for pattern matching.
constant-name Name of the constant property is specified here
constant-value Value of the constant property is specified here.
formset This element contains multiple <form> elements
form This element contains the form details.
The attributes are:
name
:

Contains the form name. Validator uses this logical name to map the validations to a Form Bean defined in the struts-config.xml file

field

This element is inside the form element, and it defines the validations to apply to specified Form Bean fields.

The attributes are:

  • property: Contains the name of a field in the specified Form Bean

  • depends: Specifies the logical names of validation routines from the validator-rules.xml file that should be applied to the field.

arg

A key for the error message to be thrown incase the validation fails, is specified here

var

Contains the variable names and their values as nested elements within this element.

var-name

The name of the criteria against which a field is validated is specified here as a variable

var-value The value of the field is specified here



Example of form in the validation.xml file is as follows:

<!-- An example form -->
<form name="logonForm">
<field property="username"
depends="required">
<arg key="logonForm.username"/>
</field>
<field property="password"
depends="required,mask">
<arg key="logonForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>

To allow front-end validation based on xml in validation.xml,the <html:javascript> tag is used.In the validation.xml file,for  example the code: <html:javascript formName="logonForm" dynamicJavascript="true" staticJavascript="true" /> generate the client side java script for the form "logonForm" . The <html:javascript> generates the client site validation script when added in jsp file.



Be the first one to comment on this page.




  Struts Tutorial eBooks

No eBooks on Struts could be found as of now.

 
 Struts Tutorial FAQs
More Links » »
 
 Struts Tutorial Interview Questions
More Links » »
 
 Struts Tutorial Articles
More Links » »
 
 Struts Tutorial News
More Links » »
 
 Struts Tutorial Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: struts validator framework,regular expression validator,web application framework,struts web application,xml validator,struts validator tutorial,struts tutorial,struts jakarta,struts validator requiredif,struts validator example,struts validator xml,struts apache,apache framework,struts validation

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.