I am having problems displaying validation errors on a JSP page. I successfully traverse my validator classes validate() method but the error messages are not displayed. I have set a default message as well as a specific message in messages.properties. I am beginning to think it may be a result of setting my form backing object to "registrationForm" instead of leaving it the default "command".
Validate code snippet:
JSP Form:Code:public void validate(Object command, Errors errors) { RegistrationForm form = (RegistrationForm) command; LOG.debug("Registration Validator - validate()"); LOG.debug("Username "+form.getUserName()+" password "+form.getPassword()); if (form == null || form.getUserName().length() == 0 ) { errors.rejectValue("userName", "required", null, "Username Required"); } if (form == null || form.getPassword().length() == 0 ) { errors.rejectValue("password", "required", null, "Password Required"); } }
Messages.properties contains only:Code:<%@ include file="/WEB-INF/jsp/include.jsp" %> <link rel='stylesheet' type='text/css' href='../../../css/prototype1.css'/> <form method="post"> <table border=0 width=100% cellspacing=0 cellpadding=2> <col align=left> <col align=left> <tr> <td colspan='2'> <h4><font color="#99999">Create Login</h4> </tr> <tr> <td colspan='2'> </tr> <tr> <td colspan="1">Username:</td> <td> <spring:bind path="registrationForm.userName"> <input type="text" name="userName" value="<c:out value="${status.value}"/>" size="30"> <span class="error"><c:out value="${status.errorMessage}"/></span> </spring:bind> </td> </tr> <tr> <td colspan="1">Email Address:</td> <td> <spring:bind path="registrationForm.emailAddress"> <input type="text" name="emailAddress" value="<c:out value="${status.value}"/>" size="30"> <span class="error"><c:out value="${status.errorMessage}"/></span> </spring:bind> </td> </tr> <tr> <td colspan="1">Confirm Email:</td> <td> <spring:bind path="registrationForm.confirmEmailAddress"> <input type="text" name="confirmEmailAddress" value="<c:out value="${status.value}"/>" size="30"> <span class="error"><c:out value="${status.errorMessage}"/></span> </spring:bind> </td> </tr> <tr> <td colspan="1">Password:</td> <td> <spring:bind path="registrationForm.password"> <input type="password" name="password" value="<c:out value="${status.value}"/>" size="30"> <span class="error"><c:out value="${status.errorMessage}"/></span> </spring:bind> </td> </tr> <tr> <td colspan="1" rowspan="1"></td> <td colspan="1"> <input type="submit" value="Submit"> </td> </tr> </table> </form>
Any suggestions? would be appreicated.Code:required=This field cannot be empty


Reply With Quote