轉換器實例在通過Application#createConverter()
創建。
Converter converter = facesContext.getApplication().createConverter(idOrClass);
等爲many abstract artifacts in JSF API的Application
遵循decorator (wrapper) pattern,就像你可以找到over all place in java.io.*
。您可以在faces-config.xml
通過<factory>
提供一個自定義的OmniFaces在沒有低於其/META-INF/faces-config.xml
:
<factory>
<application-factory>org.omnifaces.application.OmniApplicationFactory</application-factory>
</factory>
應用工廠實現歸結爲:
public class OmniApplicationFactory extends ApplicationFactory {
private final ApplicationFactory wrapped;
public OmniApplicationFactory(ApplicationFactory wrapped) {
this.wrapped = wrapped;
}
@Override
public Application getApplication() {
return new OmniApplication(wrapped.getApplication());
}
@Override
public void setApplication(Application application) {
wrapped.setApplication(application);
}
@Override
public ApplicationFactory getWrapped() {
return wrapped;
}
}
(該actual implementation是一點點更復雜的工作來解決來自較舊版本的第三方庫(如Seam,Weld和Spring WebFlow)的破碎的應用程序工廠(它們已經長期固定在他們身邊)。
的OmniApplication
實施歸結爲:
public class OmniApplication extends ApplicationWrapper {
private final Application wrapped;
private final ConverterManager converterManager;
public OmniApplication(Application wrapped) {
this.wrapped = wrapped;
converterManager = BeanManager.INSTANCE.getReference(ConverterManager.class);
}
@Override
public Converter createConverter(String converterId) {
Converter converter = converterManager.createConverter(getWrapped(), converterId);
return (converter != null) ? converter : super.createConverter(converterId);
}
@Override
public Application getWrapped() {
return wrapped;
}
}
你看,有代表團ConverterManager
正在發生的事情。