Skip to content

Latest commit

 

History

History
43 lines (29 loc) · 2.32 KB

bean-validation.adoc

File metadata and controls

43 lines (29 loc) · 2.32 KB

Bean Validation Module

Introduction

The main feature of the Bean Validation module is to provide CDI integration in to ConstraintValidator\`s. This allows you to inject CDI objects, EJBs etc in to your validators.

Scoping

ConstraintValidator`s will inherit whatever scope as defined in the bean class. Inherently, a `ConstraintValidator` may be invoked by multiple threads so please keep that in mind when using them. You should consider using at least RequestScoped validators.

Code Requirements

There are no compile dependencies to use the Bean Validation module. You simply need to override the factory, either in Java:

Validation.byDefaultProvider().configure().constraintValidatorFactory(new CDIAwareConstraintValidatorFactory()).buildValidatorFactory()

Or in XML:

<validation-config xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration">
    <constraint-validator-factory>org.apache.deltaspike.beanvalidation.impl.CDIAwareConstraintValidatorFactory</constraint-validator-factory>
</validation-config>

And then you can simply build your `ConstraintValidator`s based on CDI programming rules.