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.
Validation (Int Validator) Struts 2 Framework provides in-built validation functions to validate user
inputs. These validation functions are sufficient for any normal web
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 "").
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.
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.
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.
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.
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.
July 6, 2012
Action never call after error occured.
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 ?