Suppose my form fields map to an Integer, Short, etc., and the input is invalid (non-numeric).
I get the following in my errors map upon form submission:
Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Short' for property 'property'; nested exception is java.lang.NumberFormatException: For input string: "a"
I need to show a custom, user-friendly message. This doesn't work for me, it never comes here:
@ExceptionHandler(NumberFormatException.class)
public String handleNumberConversion(NumberFormatException nfe)
{
return "error.invalidNumberFormat";
}
BindException doesn't work either - in fact even a generic Exception in the method signature won't get activated.
EDIT: 2nd Attempt: I even tried this, this doesn't work either in my Resource Bundle, either:
# SpringMVC Error Overrides
typeMismatch.java.lang.NumberFormatException=A NumberFormatException occurred.
typeMismatch.java.lang.Short={0} is an invalid value.
typeMismatch.java.lang.Integer={0} is an invalid value.
Also, I need to get some details from the Binding process exception, such as the field that was being bound and the current value, because my custom error message shows this information.