In this video, implement a custom constraint that ensures the stock code length is only three characters and all in uppercase.
- [Instructor] The bean validation API…provides another more fine-grained approach…to creating your own constraints.…You can create your own constraint from scratch,…so that's what I'm doing now.…Let's have a look at the stock class.…Here you can see the code filled this annotate…with three constraints.…I think we can do better,…and convert them into a custom constraint.…So the first thing I need is a new annotation.…Which I'll call stock code.…So I'll just go into here,…now create new class,…and I'll call it StockCode like so,…and of course this is going to be an annotation,…so just need to create it does an interface,…like so.…
And now I need to start adding some annotations…to this class.…So I'm going to start with the target annotation.…So,…@Target…and where do I want to use this annotation?…Well let's think,…I'm just going to put it on the method,…like so,…system with this,…to make it neater,…like so,…and I'm going to add the field,…and then let's add the annotation type,…and we can add also the constructor,…and let's say parameter,…
In this course, you can journey through the many constraints that are built into the 2.0 version of the Bean Validation API, as well as the additional constraints provided by the Hibernate Validator 6.0. Learn Bean Validation in a practical way while you build a functioning web application. Instructor Alex Theedom shows how to extend the API with custom constraints and how to internationalize validation failure messages. Plus, learn advanced techniques such as cross-field and cross-parameter validation, and how Bean Validation integrates with other Java EE technologies such as JAX-RS, Java Persistence API (JPA), and JavaServer Faces (JSF). By the end of this course, you will have gained practical experience of using Bean Validation in a real web application and be able to implement what you have learned in your own Java applications.
- What is Bean Validation?
- Applying the built-in constraints
- Applying Hibernate constraints
- Designing custom constraint validators
- Managing and configuring validation failure messages
- Creating custom composite constraints
- Creating custom validation constraints
- Cross-field and cross-parameter validation
- Integration with RESTful web services (JAX-RS)