Thursday, 15 March 2012

How do I customize error message for an invalid date format in Spring 3? -



How do I customize error message for an invalid date format in Spring 3? -

i'm using spring 3.1.1.release. want customize error message displayed invalid date format in java.util.date fields in model. here model …

public class contractform { … private date activationdate; private date expirationdate; … }

i have setup in properties bundle …

typemismatch.contractform.activationdate=the activation date format should of form mm/dd/yyyy typemismatch.contractform.expirationdate=the expiration date format should of form mm/dd/yyyy

and have registered custom java.util.date editor in controller …

@initbinder public void initbinder(webdatabinder binder) { final dateformat dateformat = new simpledateformat(contract.date_format); dateformat.setlenient(false); binder.registercustomeditor(date.class, new customdateeditor(dateformat, true)); ... }

however, when submit form invalid date, don't desired error message, instead getting like, 'failed convert property value of type java.lang.string required type java.util.date property activationdate; nested exception java.lang.illegalargumentexception: not parse date: unparseable date: "02012013"'

how desired error message?

spring date validation message

No comments:

Post a Comment