Spring web data binders : override default error message
When binding a HTML form to a Java bean using Spring technology, you may have type conversions issues that will display an ugly error message.
For instance, you have an input that binds to a BigDecimal attribute in a Java bean.
If you type in letters in your input and you submit the form, the following error will be displayed :
Failed to convert property value of type java.lang.String to required type java.math.BigDecimal for property myBigDecimalProperty; nested exception is java.lang.IllegalArgumentException: Could not parse number: Unparseable number: “thisisnotabigdecimalvalue”
If a user see that kind of error, he will throw his computer through the window and claim he has been attacked by north korean hackers.
You should solve that issue by adding new messages in a resource bundle file :
For a specific type :
For a specific Java property :
Have a look to this piece of documentation to understand how error messages are built.