JavaScript

Validators: Introducing Struts Validator Framework

Validation is an important part of many web applications. Input can be validated on the client side or the server side. The Validator framework can be used to simplify input validations on both sides. This tutorial explains how.

Client side validation is the holy grail of web development. Any web application that does not utilize forms to gather user information would be a rarity. For a developer, web forms are synonymous with input validation. The process of validating the input can be carried out at two places -- either at the client side or at the server-side.

Server-side validation is not a popular choice in many situations due to the round trip factor. That means the data is validated at server-side and the result is sent to the client. So just to validate, an extra request-response cycle is required. Hence, client-side validation is preferred over server-side validation.

The arrival of JavaScript gave the needed boost to client-side validation. But as the number of validations to be performed on the entry fields increased along with the number of fields to be validated, JavaScript based validations became complex. Script libraries were built to contain this complexity. But still something was amiss. The web development itself was undergoing a transformation. A declarative approach based on XML was replacing the programmatic approach, especially in enterprise application. And when the platform is J2EE, where the declarative approach is a norm, how can input validations be left behind to be done solely through JavaScript?

It was in such a situation that the Validator framework came to the forefront. So, what is the Validator framework and how can it be used to simplify input validations -- both the client as well as the server-side? I will be discussing these aspects in this part of tutorial.