Custom validation with JSR-303/Bean Validation

In the previous sections, we learned how to use standard JSR-303 Bean Validation annotations to validate fields of our domain object. This works great for simple validations, but sometimes we need to validate some custom rules that aren't available in the standard annotations. For example, what if we need to validate a newly added product's ID, which should not be the same as any existing product ID? To accomplish this type of thing, we can use custom validation annotations.

Time for action - adding Bean Validation support

In this exercise we are going to learn how to create custom validation annotations and how to use them. Let's add a custom product ID validation to our Add new product page to validate ...

Get Spring MVC Beginner’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.