Spring MVC 3: CustomDateEditor working but there is a validation error (BindingResult) -


i have problem validation error displayed when submit form empty date in resulting web page:

failed convert property value of type java.lang.string required type  java.util.date property datefin; nested exception  java.lang.illegalargumentexception: not parse date: unparseable date: "" 

my controller looks this:

    @controller     @sessionattributes     @lazy     public class mycontroller extends abstractmvpaction {         @requestmapping(value = "/secured/cp/saveprogram")         public string enregistrerprogramme(@modelattribute program program,                  bindingresult bindingresult, modelmap model){             if(bindingresult.haserrors()){                 model.put("program", program);                 return "/secured/cp/showprogram"             }else{                 // ... saves programme                 model.put("program", null);                 return "/secured/cp/backtootherpage"             }         }         @initbinder         public void initbinder(webdatabinder binder) {             binder.registercustomeditor(date.class, new customdateeditor(                     new simpledateformat("dd/mm/yyyy"), false));         }     } 

when debug method, can see object fine, modif did reported, date null, bindingresult.haserrors() returns true , according me shouldn't.

i used have validation annotations in program object , @valid annotation removed them , still have problem.

i have read lot's of similar issues , every time solution @initbinder/customdateeditor. there , guess it's working, dates displayed way want (this not case before add it) , can submit them provided it's not empty.

thank's in advance, i'm starting go crazy...

you've constructed customdateeditor explicitly disallows empty string. check javadoc constructor you're using, when boolean argument false, passing empty string editor causes illegalargumentexception you're seeing.

try this:

    @initbinder     public void initbinder(webdatabinder binder) {         binder.registercustomeditor(date.class, new customdateeditor(                 new simpledateformat("dd/mm/yyyy"), false));     } 

Comments