Java Reference
In-Depth Information
<tr>
<td>Last Name:</td>
<td><c:out value="${policydetails.lastName}"/></td>
</tr>
<tr>
<td>Age :</td>
<td><c:out value="${policydetails.age}"/></td>
</tr>
</table>
</form>
</body>
</html>
Form Validation
In the form shown in Listing 3-24, the fields have certain restrictions. The first name
and last name fields are mandatory, and age must be an integer. It is possible to check
these restrictions using client-side JavaScript. However, most applications these days
require cross-browser support, and JavaScript is the most significant obstacle to this.
The alternative option is server-side form validation. As shown in Figure 3-12, the
SimpleFormController supports server-side form validation.
Spring MVC supports two types of validators:
Programmatic validators : These implement the validations with customized logic.
These are generally carried out by classes that implement the Validator interface.
For the sake of simplicity, I will concentrate on this variety only.
Declarative validators : These implement the validations via configuration. Spring
MVC integrates with two validation frameworks—Commons Validator and
VALANG—to provide this feature. The integration and usage of these two are a
huge subject and beyond the scope of this topic. For detailed treatment on these
two frameworks, refer to Expert Spring MVC and Web Flow (Apress, 2006).
The first step to form validation is creating an implementation of the Validator inter-
face, as shown in Listing 3-30. The implementation of the supports method is necessary,
because it informs the Spring MVC framework whether a validator is applicable for a
 
Search WWH ::




Custom Search