emmanuel wrote:
I think validateProperty is actually a very nice approach. That or the ability to filter ConstraintViolations by propertyPath
I want to run the validation in the presentation logic, and not in the view, so if using validateProperty() I would have to keep the validation result for each property in a separate list to hand over to the view. I guess that would be kind of messy unless storing the violations inside the same view DTO as the data, ie:
Code:
class MyViewDto {
PhoneNumber phone;
List<ConstraintViolation> phoneViolations;
...
}
-or-
class MyViewDto {
PhoneNumberAndViolations phone;
...
}
but I get a little awkward feeling from mixing data and validation results. But maybe it's ok as it is view data?
Maybe the filtering solution is cleaner, imagining that the view should get a ConstraintViolation list separately from MyViewDto and then have matching property names specified inside the view code for filtering...
Thoughts?