Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to change the default error messages being thrown by Spring.

I basically have this form. Format of the date should follow "mm/dd/yyyy"

<p>
    <label class="label">Start Date</label>
    <form:input path="dteStartDate" /> 
    <form:errors path="dteStartDate"/>
</p>

Everything works fine, but during binding I get this message added by the form:error tag.

Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property dteStartDate; nested exception is java.lang.IllegalArgumentException:

Could not parse date: Unparseable date: "2010/11/19"

Can I customize this? So that instead of these I could show something like this:

Invalid Date Format. Format should be "mm/dd/yyyy"

This is Spring MVC 2.5.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
224 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to define a MessageSource to resolve error code to the message. Error codes are built as described here (so you'll have typeMismatch.<objectName>.dteStartDate).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...