3

ポストコンストラクトアノテーションはバリデーターでサポートされていませんか?

アプリケーションスコープのjndiservicelocatorBeanがあり、これを管理プロパティとしてバリデーターに挿入します。

@ManagedProperty(value = "#{jndiServiceLocatorBean}")
private final JndiServiceLocatorBean jndiServiceLocatorBean = null;

必要なリモートBeanを初期化するためのpostconstruct注釈付きメソッドが呼び出されることはないため、リモートBeanはnullのままです。

private UserBeanRemote userBeanRemote = null;

@PostConstruct
public void postConstruct()
{
    this.userBeanRemote = (UserBeanRemote) this.jndiServiceLocatorBean.getRemoteBean(UserBeanRemote.class);
}
4

1 に答える 1

3

が。の代わりにまたはValidatorとして注釈が付けられている場合にのみ機能します。@ManagedBean@Named@FacesValidator

代わりに通常のコンストラクターを使用してください。

@FacesValidator("fooValidator")
public class FooValidator implements Validator {

    private UserBeanRemote userBeanRemote;

    public FooValidator() {
        FacesContext context = FacesContext.getCurrentInstance();
        JndiServiceLocatorBean jndiServiceLocatorBean = context.getApplication().evaluateExpressionGet(context, "#{jndiServiceLocatorBean}", JndiServiceLocatorBean.class);
        this.userBeanRemote = (UserBeanRemote) jndiServiceLocatorBean.getRemoteBean(UserBeanRemote.class);
    }

    // ...
}

JSF 2.2@ManagedBeanで計画されている以外のJSFアーティファクトでの依存性注入のサポート(仕様問題763)。

参照:

于 2012-05-28T19:34:52.677 に答える