I’ve implemented a ReloadableResourceBundleMessageSource in my Spring MVC application which I use to display prettier error messages for binding exceptions. The problem I’m having is that, due to a company policy, these errors must be displayed in the following format:
[inputData] is not a valid [fieldName].
The field name is accessible by default in my message properties file (as the {0} argument), but I can’t figure out a way to display the invalid user input. Is this possible?
Yes,
errors Tag does not allow you get the “value” supplied by your user – See link
Suppose here goes your errors.properties (root of the classpath) file (Notice i am using just one {0} argument)
When validating your command object, you do as follows
UPDATE
But to get your goal, you must provide a custom messageSource (Notice implements instead of extends)
So define your PolicyMessageSource as messageSource
Be aware you must define just one messageSource instance called messageSource. Notice i am using ResourceBundleMessageSource instead. You must check out the same approach when using ReloadableResourceBundleMessageSource. Keep this in mind.