@ApplicationScoped public class ConverterManager extends Object
The @FacesConverter
is by default not eligible for dependency injection by @Inject
nor @EJB
.
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 converter instance into the JSF application context,
and hence you won't be able to make use of Application.createConverter(String)
on it. Further it also breaks
the power of forClass
attribute, i.e. you can't register a JSF converter for a specific type anymore and
you'd need to explicitly declare it everytime.
Initially, this should be solved in JSF 2.2 which comes with new support for dependency injection in among others all
javax.faces.*.*Factory
, NavigationHandler
, ResourceHandler
,
ActionListener
, PhaseListener
and SystemEventListener
instances.
The Converter
and 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 @Advanced
annotation.
OmniFaces solves this by implicitly making all FacesConverter
instances eligible for dependency injection
without any further modification, like as JSF 2.2 would initially do, hereby providing a transparent
bridge of the code to the upcoming JSF 2.3.
The ConverterManager
provides access to all FacesConverter
annotated Converter
instances which are made eligible for CDI.
OmniApplication
,
OmniApplicationFactory
Constructor and Description |
---|
ConverterManager() |
Modifier and Type | Method and Description |
---|---|
Converter |
createConverter(Application application,
Class<?> converterForClass)
Returns the converter instance associated with the given converter for-class,
or
null if there is none. |
Converter |
createConverter(Application application,
String converterId)
Returns the converter instance associated with the given converter ID,
or
null if there is none. |
public Converter createConverter(Application application, String converterId)
null
if there is none.application
- The involved JSF application.converterId
- The converter ID of the desired converter instance.null
if there is none.public Converter createConverter(Application application, Class<?> converterForClass)
null
if there is none.application
- The involved JSF application.converterForClass
- The converter for-class of the desired converter instance.null
if there is none.Copyright © 2012–2015 OmniFaces. All rights reserved.