Java Reference
In-Depth Information
Listing 3-32. WEB-INF/classes/
mandatoryfirstname.policydetails.firstName=First name field is mandatory
mandatoryfirstname.policydetails.mandatorylastname=Last name field is mandatory
mandatoryfirstname.policydetails.mandatoryAge=Age å
field is mandatory and should be an integer(0-9)
Note that the message keys are different from the error keys. This is because the
MessageCodesResolver implementation converts the error key to append the command
name and field name. Finally, we also need to modify the JSP slightly to display validation
error messages alongside the corresponding fields. For this purpose, I will use the tag
library provided by Spring to simplify the development of JSP-based views. Listing 3-33
shows the modified JSP.
Listing 3-33. WEB-INF/jsp/createPolicy.jsp
<%@ taglib prefix="form" uri="" %>
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fmt" uri="" %>
.error { color: red; }
<form:form action="" method="POST" commandName="policydetails">
First Name <form:input path="firstName"/>
<form:errors path="firstName" cssClass="error"/><br/>
Last Name <form:input path="lastName"/>
<form:errors path="lastName" cssClass="error"/><br/>
Age <form:input path="age"/> <form:errors path="age" cssClass="error"/><br/>
<input type="submit" value="Save" />
Search WWH ::

Custom Search