The @FacesConverter 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
FacesConverter instances eligible for dependency injection without any further modification. In order to utilize OmniFaces managed
converter, simply remove the Faces native managed=true attribute.
The ConverterManager provides access to all FacesConverter annotated Converter 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 FacesConverter 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 converter class.
AmbiguousResolutionException
In case you have a FacesConverter annotated class extending another FacesConverter annotated class which in turn extends a standard
converter, then you may with bean-discovery-mode="all" face an AmbiguousResolutionException. This can be solved by placing
Specializes annotation on the subclass.
Converters with special Class constructor
By default, CDI only instantiates beans via the default constructor. In case a converter for a class is created, and the returned converter does not have a
default constructor, or has a single argument constructor that takes a Class instance, then this converter will not be made eligible
for CDI. This change was added in OmniFaces 2.6 as per issue 25.
@FacesConverter(managed=true) compatibility
When the converter is managed with the managed=true attribute set on the FacesConverter annotation, then the converter won't be managed
by OmniFaces and will continue to work fine for Faces. But the <o:converter> 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 TypeMethodDescriptioncreateConverter(Application application, Class<?> converterForClass) Returns the converter instance associated with the given converter for-class, ornullif there is none.createConverter(Application application, String converterId) Returns the converter instance associated with the given converter ID, ornullif there is none.voidinit()
-
Constructor Details
-
ConverterManager
public ConverterManager()
-
-
Method Details
-
init
-
createConverter
Returns the converter instance associated with the given converter ID, ornullif there is none.- Parameters:
application- The involved Faces application.converterId- The converter ID of the desired converter instance.- Returns:
- the converter instance associated with the given converter ID, or
nullif there is none.
-
createConverter
Returns the converter instance associated with the given converter for-class, ornullif there is none.- Parameters:
application- The involved Faces application.converterForClass- The converter for-class of the desired converter instance.- Returns:
- the converter instance associated with the given converter for-class, or
nullif there is none.
-