Sorry for my dumb question and bad English. i trying to make some validation on user change password menu in my new Developed Web using Spring MVC.
i follow instruction from How to perform Spring validation in MultiActionController?
i write this code :
public ModelAndView hanldeBindException(HttpServletRequest request, HttpServletResponse response, ServletRequestBindingException bindingException) {
BindException bindException = (BindException) bindingException.getRootCause();
ModelMap modelmap = new ModelMap();
ChangePasswordForm cpForm = new ChangePasswordForm();
cpForm.setUsername(SessionHelper.getUsername());
modelmap.addAttribute("ChangePasswordForm", cpForm);
return new ModelAndView("changepassword").addAllObjects(bindException.getModel()).addObject("ChangePasswordForm", cpForm);
}
and in my jsp :
<form:form action="update.htm" commandName="ChangePasswordForm" >
<form:errors path="*" cssClass="errorblock" element="div" />
<table class="form">
<tr>
<td class="col1"><label>User Name :</label></td>
<td class="col2"><form:label path="username" >${ChangePasswordForm.username}</form:label></td>
</tr>
<tr>
<td><label>Old Password :</label></td>
<td><form:password path="oldPassword" id="oldPassword"></form:password>
<form:errors path="oldPassword" cssClass="error" /></td>
</tr>
<tr>
<td><label>New Password :</label></td>
<td><form:password path="newPassword"></form:password>
<form:errors path="newPassword" cssClass="error" /></td>
</tr>
<tr>
<td><label>Confirm New Password :</label></td>
<td><form:password path="confirmNewPassword"></form:password>
<form:errors path="confirmNewPassword" cssClass="error" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="submit" ></td>
</tr>
</table>
</form:form>
but it does not appear any error on my screen when i try negative test like empty field. when i try to print out
System.out.println("UserController::hanldeBindException::1" + bindException.getObjectName());
it show the object name is "command" instead of my command name in jsp which is "ChangePasswordForm". When i try to change that commandName to "command" it works. But i just curious is there some way to setObjectName in BindException Class or you have another way to use custom name instead of default "command" Object Name??
UPDATE
My Validation works since i change commandName to "command" to like this :
<form:form action="update.htm" commandName="command">
<!-- Form Field and Error define here -->
</form:form>
and of course do some adjustment in my controller also. if i change it to another name it wont work anymore.
I use Spring Framework 3.0.2 RELEASE.