View Full Version : Date Format Validation
ksriram
May 29th, 2007, 02:06 AM
Hi,
I want to validate the date format in the page.I learn t that it can be done by using the ResourceMessageBundleSource.
Can someone site a an example on this.
sami25
May 29th, 2007, 05:03 AM
Hi,
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, true));
}
put the above code in your controller and during bind time itself spring will validate it, but it will throw an illegal argument exception if bind fails.
the command bean must have Date.class attribute.
In the jsp make the textfield readonly.
ksriram
May 29th, 2007, 05:32 AM
I have already put that code in the controller.
My doubt is, how to display that error message in the jsp page.
Can u give me an example
macar
May 29th, 2007, 05:41 AM
Use form:errors tag:
<form:input path="your_date"/>
<form:errors path="your_date"/>
In case of incorrect input, the binding fails and a SimpleFormController (I assume that you use SFC) will redirect user back to the form view and appropiate message should be displayed.
ksriram
May 29th, 2007, 05:53 AM
I got it.Thanks for the input.
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.