ANNOUNCE: Metadata based validation for JavaServer Faces – Part 1
posted 6 years ago
I am pleased to announce a new article on JSF Central. In the first article of this series, Gerhard Petracek introduces MyFaces ExtVal, a JSF-centric validation platform that provides advanced features not yet available in other JSF validation frameworks.
Here is an excerpt:
Validation is an important part of every business application. Therefore JavaServer Faces (JSF) provides a specific phase for it that covers the needs of many web applications. However as time passed, new features and specifications were introduced by the Java Community Process (JCP). One feature that became an important part of Java software development was metadata via annotations. For instance, the Java Persistence API (JPA) uses annotations to simplify development. With annotations, information is attached to the artifact it belongs to. This article illustrates how they can be applied to validation with JSF.
In JSF, you have to define validation logic for every input component to be validated. In several cases this means you must violate the "Don't Repeat Yourself" (DRY) principle. A simple example is a property of an entity that is specified as required in JPA. Even though this information is already available in the model, you also have to specify that the input component bound to the mentioned property is required, by setting the required attribute to true. If the model changes, you have to go though all pages of your JSF application and change the corresponding components. You can resolve such restrictions with MyFaces Extensions Validator framework (aka MyFaces ExtVal).