Time for action – adding custom validation support
In this section, you will learn how to create custom validation annotations and use them. Add a custom product ID validation to your add product page to validate duplicate product IDs by performing the following steps:
Create an annotation interface called
ProductId
(ProductId.java
) under the packagecom.packt.webstore.validator
in the source foldersrc/main/java
. Then, add the following code snippet in it:package com.packt.webstore.validator; import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; import javax.validation.Constraint; import javax.validation.Payload; @Target( { METHOD, FIELD, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy...