JavaScript
  Home arrow JavaScript arrow Page 4 - 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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
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 / 73
    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 - Provide the appropriate ActionForm Class


    (Page 4 of 4 )

    The next part is providing and configuring the ActionForm. I am using the DynaActionForm, so the approach is declarative. The declaration of the form bean in struts-config.xml is:

              <form-bean name="loginFormBean"     type="org.apache.struts.validator.DynaValidatorActionForm">
              <form-property name="form_login" type="java.lang.String"/>
              <form-property name="form_password" type="java.lang.String"/>
              </form-bean> 

    The only difference is with the type attribute. With normal forms it is “org.apache.struts.action.ActionForm,” whereas here it is ”org.apache.struts.validator.DynaValidatorActionForm."

    Enable the error handling in JSP page

    To use the server-side validation, the <html:errors> tag has to be used. But to enable client side validation certain additional tags (both HTML as well as Struts HTML) have to be supplied.

    First the <javascript> custom tag of the HTML tags category in Struts must be placed within the <head> tag.

    <head>
    <link rel="stylesheet" href="css/print.css" type="text/css"
    media="print">
     
    <link rel="stylesheet" href="css/styles.css" type="text/css">
    <link rel="stylesheet" href="css/forms.css" type="text/css">
    <html:javascript formName=" loginFormBean" />
    </head>

    Next add an onSubmit handler to the <html:form> tag.

      <html:form action="LoginAction.do" onSubmit=”return validateLoginFormBean(this);”>
    :
    :
    </html:form>

     

    The framework generates the required JavaScript code automatically. But the naming convention is such that the validate prefix is used with the form bean name to generate the onSubmit() handler. Hence the snippet ”return validateLoginFormBean(this);”.

    Hook the Validator with the Struts framework

    The last step is to configure the struts-config.xml so that the Struts framework can communicate with the Validator framework. This is done using the plugin tag of struts-config.xml. First declare the plug-in using the <plugin> tag. The className attribute is used to specify the class implementing the plug-in functionality. Since the Validator framework has to be used the className has the value “org.apache.struts.validator.ValidatorPlugIn”

    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
          :
             :
    </plug-in>

    Next the path where the XML files are placed must be given. For this use property and value attributes of <set-property> tag.

    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
        <set-property property="pathnames"
            value="/WEB-INF/validator-rules.xml,/WEB-INF/validations.xml"/>
     </plug-in>

    The value of the property is pathnames and the value of value is the path where the XML files are kept. Now the application is ready to be used.

    This brings us to the end of the first part of the Validator framework tutorial. So what are other features provided by this framework and how can they be utilized to reduce development time? I will give details in the next part. Till next time.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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

    - 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
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway