I want to use ManagedBean
in my Converter
. The ManagedBean
is responsible for getting data from database. In Converter
I want to convert string into object which must be get from database.
This is my Converter
@FacesConverter(forClass=Gallery.class, value="galleryConverter")
public class GalleryConverter implements Converter {
// of course this one is null
@ManagedProperty(value="#{galleryContainer}")
private GalleryContainer galleryContainer;
@Override
public Object getAsObject(FacesContext context, UIComponent component, String galleryId) {
return galleryContainer.findGallery(galleryId);
...
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object gallery) {
...
}
}
I know that galleryContainer
will be null and if I want to inject ManagedBean
into Converter
I can mark it as ManagedBean
too. The problem is that I want to do it in beautiful way, I don't want to look for some 'strange solution'. Maybe the problem is in my application? Maybe there is some other good solution to create object which must get data from database and used in converter? I want also to mention that I will prefer to use DependencyInjection
instead of creating new object using new
statement (it is easier to test and maintain). Any suggestions?