Extending CSV with Bean Validation
Although the Bean Validation API defines a whole set of standard constraint annotations, one can easily think of situations in which these standard annotations will not suffice. For these cases, you will be able to create custom constraints for specific validation requirements. The Client Side Validation API in PrimeFaces works seamlessly with custom constraints.
In this recipe, we will develop a special custom constraint and validators to validate a Card Verification Code (CVC). CVC is used as a security feature with a bank card number. It is a number with a length between three and four digits. For instance, MasterCard and Visa require three digits, and American Express requires four digits. Therefore, the CVC validation will depend on the selected bank card. The user can select a bank card using p:selectOneMenu
, type a CVC into p:inputText
, and submit the input after that.
How to do it…
We will start with a custom annotation used for the CVC field...