PDA

View Full Version : How to get custom message


neeraj_cmu
Aug 29th, 2005, 02:40 AM
Spring comes with custom editor for BigDecimal. In case of wrong user input the default message the comes on screen is


Failed to convert property value of type [java.lang.String] to required type [java.math.BigDecimal] for property buyUpDownAmount; nested exception is java.lang.NumberFormatException: For input string: "sss"


I was wondering if there is an easy way to customise this message.

Thanks.

zorak
Aug 29th, 2005, 09:25 AM
If you declare a messageSource (a simple .properties file)


<bean
id="messageSource"
class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename">
<value>messages</value>
</property>
</bean>


you can declare things like
typeMismatch.java.lang.Integer={0} must be a number
This even gets localized. So for germany messages_de.properties is used.