A long wandering and eventful journey
Validations
Published on July 7, 2005 By ApKa In Tutorials
In this article:

We will verify that the Username is not blank, has more than 5 character and less than 15 characters.

If the user makes valid entries , a successful logon page is displayed else an appropriate error is displayed.

First we require to add some entries in our application.properties file.

entryform.userName = User Name
entryform.passwordnotpatch = The Passwords entered do not match.Please Enter again

These entries will be used to display the error message to the user.

The basic messages like

errors.maxlength
errors.minlength
errors.required

are already available in application.properties file.

Now we will start with our validations:

1. We will verify that the Username is not blank, has more than 5 character and less than 15 characters
This requires updating struts-config.xml
action path="/entryScreen" type="strutsTutorial.EntryAction" name="EntryForm" attribute="entry" validate="true" input="/pages/Error.jsp"
forward name="success" path="/pages/success.jsp"

/action

The attribute field will be used to match this entry in the validation.xml.


We will update our validation.xml file now for the required attribute:

This is simple.

The form names will match on the attribute property : "entry"

The field to be validated: " userName "

“depends” define the rules on which validation is done : required,minlength,maxlength"


Sine the validations have been added on UserName field, so if we leave user name blank or enter less than 5 or more than 11 characters , we will see error.jsp, displaying the error message.

In the next posting , we will verify that the password and password check field are same.





"

Comments
No one has commented on this article. Be the first!