-
Mar 12th, 2010, 01:03 PM
#1
JSR303 Custom Messages for Composed Classes
I am really stuck on this one. I have JSR303 validation working perfectly, but don't know how to customize messages on composed class.
For example, we have a class call NanpPhoneNumber annotated with JSR303 annotations and generic messages.
We compose NanpPhoneNumber into other objects like Doctor, Pharmacy, Consumer, etc. Because the errors are making their way to the top of a complex form, we'd like to take the "{com.example.nanp.areaCodeMissing}" generated by violation constraints on the composed NanpPhoneNumber (ie, doctor.phoneNumber), and change it to "{com.example.DOCTOR.nanap.areaCodeMissing}". Or otherwise mutate the validation constraint failure into a more contextualized message.
In other words, how can I have a standard class, annotated correctly to validate the object, but change the validation failure messages to be meaningful in the used context? Either through Spring 3.x or the JSR303 framework.
If anyone has has some suggestions I'd really appreciate it!
-
Mar 13th, 2010, 08:06 PM
#2
Ah ha. Found the answer in a bug report when a generous user supplied some excellent code that got me on the right track: https://jira.springsource.org/browse/SPR-6407. We are using the the poster's method for errors appearing with the field. For global errors (top of the page) we investigate the constraintViolation.getPropertyPath () to generated a key the the Errors implementation (BindingResult) will look up using standard Spring logic. I was too focused on the JSR303 side to see the solution.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules