I read a lot of manuals about the JSR 303 specification, but I don't see any example ready for release. Everywhere is described how to get an object Set<Constraintviolation<T>>.
Example:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
Set<ConstraintViolation<Car>> violations = validator.validate(car);
But what's next? I want to inform the handler (client) of the method that this method parameter is in an inconsistent state.
What should I do with Set<ConstraintViolation<Car>>? Do I need to manually iterate over Set<ConstraintViolation>, collecting all error messages on a single line, and then throw an exception with these messages?
Or are there even more convenient ways out of the box?
Or is it better to provide a validatemethod inside each bean?
source
share