Spring @InitBinder for joda time
jodatime, spring, spring-mvc
Solution
When you use command objects, then a complete different, more elegant approach would be possible:using `@DateTimeFormat` annotation.
public class CommandObject {
@DateTimeFormat(pattern="yyyy/MM/dd hh:mm:ss a")
public Date myDate();
}
@Controller
public class ControllerClass{
@RequestMapping("/myUrl")
public ModelAndView(CommandObject c) {...}
}
(@See this blog for some example formatter)
Problem
I have an initbinder for java.util.Date: ``` @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat( Constants.DATE_PICTURE); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor( dateFormat, true)); ``` What can one use to bind a joda time LocalDateTime? I'm using Spring 3.1