Home Struts Struts2 Validations Struts 2 Validation
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Struts 2 Validation

Advertisement
User input validations are integral part of any web application.

Struts 2 Validation

     

User input validations are integral part of any web application. With the release of Struts 2, validation are now much easier and robust. Struts 2 support Ajax based and even server side validations. Struts 2.0 action relies on the XWork validation framework. The XWork framework runs the validation rules before executing the action. Struts 2 also provides the facility to define validation rules in your action class using Java 5 annotations. 

  1. Struts 2 Validation (Int Validator)
    Struts 2 Framework provides in-built validation functions to validate user inputs. These validation functions are sufficient for any normal web application.

  2. Struts 2 RequiredString validator
    This section discusses RequiredString validator of Struts 2 framework. RequiredStringValidator checks the String field is non-null and its  length is > 0. (i.e. it isn't "").
     
  3. Struts 2 double validator
    The Double validator of Struts 2 Framework checks if the given input is double or not. If the input is not double, it generates the error message. Double validator can also be used to check the input range.
     
  4. Struts 2 Date Validator
    The Date validator in the Struts 2 Framework checks whether the supplied date lies within a specific range or not. If the value supplied does not lie in the specified range, it generates an error message.
      
  5. Struts 2 E-mail Validator
    The email validator in  Struts 2 Framework checks whether a given String field is empty or not and contains a valid email address or not. If the entered value does not match with the email type, then the e-mail validator generates an error message. 
      
  6. Struts 2 Url Validator
    The URLValidator of Struts 2 Framework checks whether the String contained within the given field is a valid URL or not. If the entered value is not a valid URL, it generates an error message.
     
  7. Validations using Struts 2 Annotations
    In this section we are going to validate our login application using Annotations in Action class. Our current login application does not validate the user against the database. Instead login name and passwords are validated against the hardcode values (User: Admin and Password: Admin) in the action class.

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 24, 2009

Related Tutorials

Ask Questions?    Discuss: Struts 2 Validation   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Atlantech Group
July 6, 2012
Action never call after error occured.

Hi, I'm starting develop my web app based on Strut2 and JQuery. I have some stupid problem with validation and I don't weither it is my config that is wrong. Whenever an error occured in my form, I could not continue running my app instead of restart all at the beginning. I remark that my problem come to the fact that the collection actionErrors or FieldErrors content something. What I need to do now is to clear these collectionn before my action get executed but I don't know how to proceed. How could I use an action clean up that clean my action ?
DMCA.com