If i want to use custom date editor i need few things to ask
1)In database do i have to set variable startDate as datetime or varchar
2)IN Person class startDate is refered as Date or String
I have controller like this
@Controller
public class MyController {
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
binder.registerCustomEditor(Date.class, editor);
}
in jsp form i have
<td><form:label path="startDate">date</form:label></td>
<td><form:input path="startdate"/></td>
But when i submit form , nothing happens
this is the other methods in controller
@RequestMapping(value = "/persons/add", method = RequestMethod.GET)
public String getAdd(Model model) {
logger.debug("Received request to show add page");
// Create new Person and add to model
// This is the formBackingOBject
model.addAttribute("personAttribute", new Person());
// This will resolve to /WEB-INF/jsp/addpage.jsp
return "hibernate/addpage";
}
@RequestMapping(value = "/persons/add", method = RequestMethod.POST)
public String add(@Valid @ModelAttribute("personAttribute") Person person, BindingResult result) {
logger.debug("Received request to add new person");
if (result.hasErrors())
return "hibernate/addpage";
else
personService.add(person);
// This will resolve to /WEB-INF/jsp/addedpage.jsp
return "hibernate/addedpage";
}
Use DateTime and Date. The Binder to convert a string to Date also looks fine as long as your input is in the dd-MM-yyyy format. Your controller has no methods though. Did you post all of your code? Do you have a form:method tag?