The @FacesValidator is by default not eligible for dependency injection by @Inject nor @EJB. It that only when the
managed=true attribute is set. But this doesn't support setting custom attributes. OmniFaces solves this by implicitly making all
FacesValidator instances eligible for dependency injection without any further modification. In order to utilize OmniFaces managed
validator, simply remove the Faces native managed=true attribute.
The ValidatorManager provides access to all FacesValidator annotated Validator instances which are made eligible for CDI.
bean-discovery-mode
Since CDI 1.1, when having a CDI 1.1 compatible beans.xml, by default only classes with an explicit CDI managed bean scope annotation will be
registered for dependency injection support. In order to cover FacesValidator annotated classes as well, you need to explicitly set
bean-discovery-mode="all" attribute in beans.xml. If you want to keep the default of bean-discovery-mode="annotated",
then you need to add Dependent annotation to the validator class.
AmbiguousResolutionException
In case you have a FacesValidator annotated class extending another FacesValidator annotated class which in turn extends a standard
validator, then you may with bean-discovery-mode="all" face an AmbiguousResolutionException. This can be solved by placing
Specializes annotation on the subclass.
@FacesValidator(managed=true) compatibility
When the validator is managed with the managed=true attribute set on the FacesValidator annotation, then the validator won't be managed
by OmniFaces and will continue to work fine for Faces. But the <o:validator> tag won't be able to set attributes on it.
- Since:
- 1.6
- Author:
- Radu Creanga <rdcrng@gmail.com>, Bauke Scholtz
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateValidator(Application application, String validatorId) Returns the validator instance associated with the given validator ID, ornullif there is none.
-
Constructor Details
-
ValidatorManager
public ValidatorManager()
-
-
Method Details
-
createValidator
Returns the validator instance associated with the given validator ID, ornullif there is none.- Parameters:
application- The involved Faces application.validatorId- The validator ID of the desired validator instance.- Returns:
- the validator instance associated with the given validator ID, or
nullif there is none.
-