-
Jan 14th, 2013, 01:58 PM
#1
Validation and Formatting
First off, I wasn't sure where to post this so I apologize if this is the wrong place.
I have a bean validator for an entity field named phoneNumber. The trouble I am having is that I would like to format this as E.164 before persisting the field. The formatting code is exactly like the validation code.
Is there a good pattern for joining formatting of data and validation in a way that allows me to throw a ConstrainViolationException if the data cannot be formatted? The only way I've come up with is to do the validation twice. Once in the constraint validator (format it but throw away the result) and again in the setter but assign the result. The other problem is that I cannot find a simple way to create a ConstrainViolationException with ConstrainViolations programmatically without using a ConstraintValidator.
Tags for this Thread
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