Validation and erroror reporting in Struts 1.1

One of the benefits of using Struts framework is declarative validation mechanism and error reporting. Struts provides validation hook so that you can implement your own validation logic in action classes. The validation can be turned on/off in action mapping using validate property.

In action class you can override validate() and it’s signature is:

public  ActionErrors validate(ActionMapping mapping, HttpServletRequest request)

Typically you validate presentation related information such as missing text or wrong format etc., If a validation error occurred for an input field, you can create an ActionError class  with message key (for internationalization purposes ) and the name of the input field. In the JSP you can use Struts <html:errors /> tag to display these errors.

Sometimes you need to validate business validation such as ‘check user alredy existed in the system’, these should be performed in actions’ perform(), I will post the details in my next blog.

Advertisements
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s