JavaScript
  Home arrow JavaScript arrow Page 3 - Validators: Introducing Struts Validator F...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Validators: Introducing Struts Validator Framework
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 74
    2005-08-31

    Table of Contents:
  • Validators: Introducing Struts Validator Framework
  • Validator Framework-What is it?
  • Validator Framework- A Real world Example
  • Provide the appropriate ActionForm Class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Validators: Introducing Struts Validator Framework - Validator Framework- A Real world Example


    (Page 3 of 4 )

    The login form is present in all web-based applications. I will be using the validations required on the user name and password fields. This login form is a part of an email client I am currently developing. To configure an application to use the Validator framework, you must take the following steps.

    Configure the Application

    To configure the application, the XML files need to be placed where the class loader would be able to access them. Though they can be placed anywhere theoretically, it is always better to place them directly inside the WEB-INF directory of the application. In my application, they are kept directly under the WEB-INF directory. Since all the versions since Struts version 1.1 contain the Validator framework as their integral part, there is no requirement to separately download them.

    Configure the validations.xml file

    The downloadable  Struts archive contains the two XML files I am using as my templates. The Validator-rules.xml doesn’t require any modification. But the validations.xml requires some modification. So let's get started. 

    The root element of validations.xml is <form-validation> tag.

    <form validation>
    :
    :
    </ form-validation>

    Next comes the tag representing the collection of form beans -- the <formset> tag. It encapsulates all the form beans present in an application.

    < form-validation>
         <formset>
    :
    :
         </formset>
    </ form-validation>

    Then the <form> tag comes. This tag corresponds to each form bean. That means if there are ten form beans in an application there will be ten <form> tags with the name attribute corresponding to the names of the form beans. The name of the form bean related to the login page(Login.jsp) is “loginFormBean,” so the value of the name attribute of the <form> tag is “loginFormBean.”

    < form-validation>
         <formset>
             
    <form name=“loginFormBean”>
    :
    :
             
    </form>
         </formset>
    </ form-validation>

    The fields that have to be validated are provided as a property attribute of the <field> tag. This tag contains one more property that is used to specify the validations to be performed on the field -- the depends property. If there is more than one validation, they can be separated by a comma. Here only mandatory field validation is needed. Hence the “depends” attribute contains the value “required.”

    < form-validation>
        <formset>
            <form name=“loginFormBean”>
                <field property=”form_login”
                depends=”required”/>
    :
    :
             
              </form>
          </formset>
    </ form-validation>

    Next is the message resource to be used to show the error message when validation fails. This is done by using the <arg0> tag. The key attribute is used to specify the key of the resource bundle related to the message to be used.

    < form-validation>
         <formset>
             <form name=“loginFormBean”>
                  <field property=”form_login”
                      depends=”required”/>
                      
    <arg0 key=”login.username”/>
    :
    :
         
              </form>
          </formset>
    </ form-validation>

    The ”login.username” is defined within the Application.properties file. The definition is as below:

    login.username=Username

    It works similarly for the password field; also, the validations are defined.

         < form-validation>
              <formset>
                   <form name=“loginFormBean”>
                        <field property=”form_login”
                             depends=”required”/>
                        <arg0 key=”login.username”/>
              
                       <field property=”form_password”
                         depends=”required”/>
                       <arg0 key=”login.password”/>
                   </form>
              </formset>
         </ form-validation>

    More JavaScript Articles
    More By A.P.Rajshekhar


       · HiThank you for reading this article. Hope it has been helpful. One request....
       · Hi Rajshekhar,I have a doubt related to Struts validations.I want to know how to...
       · HiSorry for delay in replying. Net was down here. Coming to your question,...
       · Thank you Rajesekhar.Its really helped me a lot in understanding the validation...
       · Extremely sorry for the long delay. The answer to your query is as...
       · Hi Rajshekhar, I want your help in server side validation in...
       · HiSorry for not replying for so long. I looked into your code. Its perfectly fine....
       · As you mentioned that "If the field is an html:select then the indexedlistproperty...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT