Announcement Announcement Module
No announcement yet.
Validation and Formatting Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.