java - Spring mvc Joda Datetime converter fail if invalid date -


i have domain object want have mapped jsp contains joda datetime:

public beanclass{   private long id;    @datetimeformat   private datetime start;    getters , setters... } 

i have following converter registered spring:

final class stringtojodadatetimeconverter<s, t> implements converter<string, datetime>    {       private static final datetimeformatter fmt = datetimeformat.forpattern("mm/dd/yyyy");    public datetime convert(string in) {      try{         return fmt.parsedatetime(in);      }catch(exception e){         throw new illegalargumentexception("invalid date");      }    } } 

spring hits converter before validator class , populate error messages full error

failed convert property value of type java.lang.string required type org.joda.time.datetime property sampledate; nested exception org.springframework.core.convert.conversionfailedexception: unable convert value "asdf" type java.lang.string type org.joda.time.datetime; nested exception java.lang.illegalargumentexception: invalid date

what want "invalid date" message exception.

is there way exception message "invalid date" instead of whole thing display?

you should use file messages.properites declare specific information:

typemismatch.java.util.date = invalid date 

of course should provide information file in spring-context.xml

  <bean id="messagesource" class="org.springframework.context.support.reloadableresourcebundlemessagesource">      <property name="basename" value="/web-inf/config/messages"/>      <property name="defaultencoding" value="utf-8"/>              </bean> 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -