Chapter 11. The Validator Framework
The Struts framework allows input
validation to occur inside the ActionForm
. To
perform validation
on data passed to a Struts application, developers must code special
validation logic inside each ActionForm
class.
Although this approach works, it has some serious limitations. This
chapter introduces David Winterfeldt’s
Validator framework, which was created specifically to work with the
Struts components and to help overcome some of these limitations.
The Validator allows you to declaratively configure validation routines for a Struts application without programming special validation logic. The Validator has become so popular and widely used by Struts developers that it has been added to the list of Jakarta projects and to the main Struts distribution.
The Need for a Validation Framework
Chapter 7 discussed how
to provide validation logic inside the
ActionForm
class. The solution presented there
requires you to write a separate piece of validation logic for each
property that you need to validate. If an error is detected, you have
to manually create an ActionError
object and add
it to the ActionErrors
collection. Although this
solution works, there are a few problems with the approach.
The first problem is that coding validation logic within each
ActionForm
places redundant validation logic throughout your application. Within a single web application, the type of validation that needs to occur across HTML forms is very similar. The need ...
Get Programming Jakarta Struts now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.