ManagedBean
で使いたいConverter
。はManagedBean
、データベースからデータを取得する責任があります。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) {
...
}
}
私はそれがnullになることを知っており、注入しgalleryContainer
たい場合はそれをマークすることもできます。問題は、私がそれを美しい方法でやりたいということです。私はいくつかの「奇妙な解決策」を探したくないのです。たぶん問題は私のアプリケーションにありますか?たぶん、データベースからデータを取得してコンバーターで使用する必要があるオブジェクトを作成するための他の良い解決策がありますか?また、ステートメントを使用して新しいオブジェクトを作成するのではなく、を使用することをお勧めします(テストと保守が簡単です)。助言がありますか?ManagedBean
Converter
ManagedBean
DependencyInjection
new