Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Client Side Address Validation in Struts

Client Side Address Validation in Struts Client Side Address Validation in Struts In this lesson we will create JSP page for entering the address and use the functionality provided by Validator Framework to validate the user data on the browser.

Tutorial Details:

Validator Framework emits the JavaScript code which validates the user input on the browser. To accomplish this we have to follow the following steps:
Enabling the Validator plug-in: This makes the Validator available to the system.
Create Message Resources for the displaying the error message to the user.
Developing the Validation rules We have to define the validation rules in the validation.xml for the address form. Struts Validator Framework uses this rule for generating the JavaScript for validation.
Applying the rules: We are required to add the appropriate tag to the JSP for generation of JavaScript.
Build and test: We are required to build the application once the above steps are done before testing.
Enabling the Validator plug- in
To enable the validator plug-in open the file struts-config.xml and make sure that following line is present in the file.


property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>

Creating Message Resources
Message resources are used by the Validator Framework to generate the validation error messages. In our application we need to define the messages for name, Address and E-mail address. Open the Struts\strutstutorial\web\WEB-INF\MessageResources.properties file and add the following lines:
AddressForm.name=Name
AddressForm.address=Address
AddressForm.emailAddress=E-mail address
Developing Validation rules
In this application we are adding only one validation that the fields on the form should not be blank. Add the following code in the validation.xml.


depends="required">


depends="required">


depends="required">



The above definition defines the validation for the form fields name , address and emailAddress . The attribute depends="required" instructs the Validator Framework to generate the JavaScript that checks that the fields are not left blank. If the fields are left blank then JavaScript shows the error message. In the error message the message are taken from the key defined in the tag. The value of key is taken from the message resources ( Struts\strutstutorial\web\WEB-INF\ MessageResources.properties ).
Applying Validation rules to JSP
Now create the AddressJavascriptValidation.jsp file to test the application. The code for AddressJavascriptValidation.jsp is as follows:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>


<bean:message key="welcome.title"/>






This application shows the use of Struts Validator.

The following form contains fields that are processed by Struts Validator.

Fill in the form and see how JavaScript generated by Validator Framework validates the form.

























Please Enter the Following Details

Name



Address



E-mail address



Save

Cancel








The code is used to plug-in the Validator JavaScript.
Create the following entry in the struts-config.xml for the mapping the /AddressJavascriptValidation url for handling the form submission through AddressJavascriptValidation.jsp .
path="/AddressJavascriptValidation"
type="roseindia.net.AddressAction"
name="AddressForm"
scope="request"
validate="true"
input="/pages/AddressJavascriptValidation.jsp">


Add the following line in the index.jsp to call the form.

  • Client Side Validation for Address Form


    The Address Form that validates the data on the client side using Stuts Validator generated JavaScript.

  • Building Example and Testing
    To build and deploy the application go to Struts\strutstutorial directory and type ant on the command prompt. This will deploy the application. Open the browser and navigate to the AddressJavascriptValidation.jsp page. Your browser should show the following out put.
    If the fields are left blank and Save button is clicked, browser shows the error message.
    In this lesson you learned how to use Struts Validator Framework to validate the form on client browser.


     

    Rate Tutorial:
    http://www.roseindia.net/struts/address_struts_validator.shtml

    Read Tutorial at: Click here to view the tutorial

    Rate Tutorial:
    Client Side Address Validation in Struts

    View Tutorial:
    Client Side Address Validation in Struts

    Related Tutorials:

    Validation with Java and XML schema, Part 3 - JavaWorld November 2000
    Validation with Java and XML schema, Part 3 - JavaWorld November 2000
     
    Build database-powered mobile applications on the Java platform
    Build database-powered mobile applications on the Java platform
     
    Boost Struts with
    Boost Struts with XSLT and XML
     
    Take command of your software
    Take command of your software
     
    Repair invalid cached services in the Service Locator pattern
    Repair invalid cached services in the Service Locator pattern
     
    Business process automation made easy with Java, Part 2
    Business process automation made easy with Java, Part 2
     
    A first look at JavaServer Faces, Part I
    A first look at JavaServer Faces, Part Learn how to implement Web-based user interfaces with JSF
     
    A first look at JavaServer Faces, Part 2
    A first look at JavaServer Faces, Part 2
     
    Struts best practices
    Multiple options are available for solving problems with Struts. When deciding among these alternatives, the choice must be based on parameters such as the scale of work and availability of time.
     
    JavaServer Faces Technology
    JavaServer Faces technology is a server-side user interface component framework for Java technology-based Web applications.
     
    Strut your stuff with JSP tags
    Learn how to use the custom tags from the open source Struts library and create extensions that ease the coding of properties associated with field values and user input validation. The Struts package is part of the open source Jakarta project.
     
    Welcome to the Apache Struts Tutorial
    This is the complete Struts Tutorial. Explains ActionForm Action Class Validation Framework.
     
    Open Source Web Frameworks in Java
    Open Source Web Frameworks in Java Open Source Web Frameworks in Java Struts Struts Frame work is the implementation of Model-View-Controller (MVC) design pattern for the JSP. Struts is maintained as a part of Apache Jakarta project and is open
     
    Jakarta Struts Interview Questions
    Jakarta Struts Interview Questions Jakarta Struts Interview Questions Q: What is Jakarta Struts Framework? A: Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications.
     
    Client Side Address Validation in Struts
    Client Side Address Validation in Struts Client Side Address Validation in Struts In this lesson we will create JSP page for entering the address and use the functionality provided by Validator Framework to validate the user data on the browser.
     
    Beginner to advance guide to the Apache Struts
    Beginner to advance guide to the Apache Struts The Complete Apache Struts Tutorial This complete reference of Jakarta Struts shows you how to develop Struts applications using ant and deploy on the JBoss Application Server. Ant script is provided
     
    The Struts ActionForm Class
    The Struts ActionForm Class The ActionForm Class In this lesson you will learn about the ActionForm in detail. I will show you a good example of ActionForm. This example will help you understand Struts in detail. We will create user interface to
     
    Struts Guide
    Struts Guide Struts Guide This tutorial is extensive guide to the Struts Framework. In this tutorial you will learn how to develop robust application using Jakarta Struts Framework. This tutorial assumes that the reader is familiar with the web
     
    Struts HTML Tags
    Struts HTML Tags Struts HTML Tags Struts provides HTML tag library for easy creation of user interfaces. In this lesson I will show you what all Struts HTML Tags are available to the JSP for the development of user interfaces. To use the Struts
     
    Struts Validator Framework Tutorial with Example
    Struts Validator Framework Tutorial with Example Struts HTML Tags Struts Validator Framework This lesson introduces you the Struts Validator Framework. In this lesson you will learn how to use Struts Validator Framework to validate the user
     
    Site navigation
     

     

    Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

    Copyright © 2006. All rights reserved.