- java.lang.Object
-
- org.omnifaces.cdi.converter.ConverterManager
-
@ApplicationScoped public class ConverterManager extends Object
The
@FacesConverteris by default not eligible for dependency injection by@Injectnor@EJB. It that only when themanaged=trueattribute is set. But this doesn't support setting custom attributes. OmniFaces solves this by implicitly making allFacesConverterinstances eligible for dependency injection without any further modification. In order to utilize OmniFaces managed converter, simply remove the Faces nativemanaged=trueattribute.The
ConverterManagerprovides access to allFacesConverterannotatedConverterinstances 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 coverFacesConverterannotated classes as well, you need to explicitly setbean-discovery-mode="all"attribute inbeans.xml. This was not necessary in Mojarra versions older than 2.2.9 due to an oversight. If you want to keep the default ofbean-discovery-mode="annotated", then you need to addDependentannotation to the converter class.AmbiguousResolutionException
In case you have a
FacesConverterannotated class extending anotherFacesConverterannotated class which in turn extends a standard converter, then you may withbean-discovery-mode="all"face anAmbiguousResolutionException. This can be solved by placingSpecializesannotation 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
Classinstance, then this converter will not be made eligible for CDI. This change was added in OmniFaces 2.6 as per issue 25.JSF 2.3 compatibility
JSF 2.3 introduced two new features for converters: parameterized converters and managed converters. When the converter is parameterized as in
implements Converter<T>, then you need to use at least OmniFaces 3.1 wherein the incompatibility was fixed. When the converter is managed with themanaged=trueattribute set on theFacesConverterannotation, 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:
OmniApplication,OmniApplicationFactory
-
-
Constructor Summary
Constructors Constructor Description ConverterManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConvertercreateConverter(Application application, Class<?> converterForClass)Returns the converter instance associated with the given converter for-class, ornullif there is none.ConvertercreateConverter(Application application, String converterId)Returns the converter instance associated with the given converter ID, ornullif there is none.voidinit()
-
-
-
Method Detail
-
init
@PostConstruct public void init()
-
createConverter
public Converter createConverter(Application application, String converterId)
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
public Converter createConverter(Application application, Class<?> converterForClass)
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.
-
-