@ApplicationScoped public class ValidatorManager extends Object
@FacesValidator is by default not eligible for dependency injection by
There is a workaround
for EJB, but this is nasty and doesn't work out for CDI. Another way
would be to make it a JSF or CDI managed bean, however this doesn't register the validator instance into the JSF application context,
and hence you won't be able to make use of
Application.createValidator(String) on it.
Initially, this should be solved in JSF 2.2 which comes with new support for dependency injection in among others all
Validator were initially also among them, but they broke a TCK test and were at the
last moment removed from dependency injection support.
The support is expected to come back in JSF 2.3, but we just can't wait any longer.
MyFaces CODI has support for it,
but it requires an additional
OmniFaces solves this by implicitly making all
FacesValidator instances eligible for dependency injection
without any further modification.
In Java EE 7's 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
beans.xml. This was not necessary in Mojarra versions older than 2.2.9 due to an
oversight. If you want to keep the default of
bean-discovery-mode="annotated", then you need to add
Dependent annotation to the validator class.
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.
OmniFaces 3.0 continued to work fine with regard to managed validators which are initially developed for JSF 2.2.
However, JSF 2.3 introduced two new features for validators: parameterized validators and managed validators.
When the validator is parameterized as in
implements Validator<T>, then you need to use
at least OmniFaces 3.1 wherein the incompatibility was fixed. When the validator is managed with the new JSF 2.3
managed=true attribute set on the
FacesValidator annotation, then the validator won't be
managed by OmniFaces and will continue to work fine for JSF. But the <o:validator> tag won't be able to
set attributes on it.
|Constructor and Description|
|Modifier and Type||Method and Description|
Returns the validator instance associated with the given validator ID, or
public Validator createValidator(Application application, String validatorId)
nullif there is none.
application- The involved JSF application.
validatorId- The validator ID of the desired validator instance.
nullif there is none.
Copyright © 2012–2021 OmniFaces. All rights reserved.