1

これを使用して、EL Expression で定義されているマネージド Bean メソッドを呼び出す必要があります。EL式を使用してマネージドBeanメソッドを呼び出す方法のような例はありますか?

ここでは、マネージド Bean の種類がわかりません。しかし、私はEL式を知っています。そのため、特定のマネージド Bean に型キャストすることはできません。

式は次のとおりです。#{phaseListenerBean.compListener}

compListenerコードでメソッドを呼び出すにはどうすればよいphaseListenerBeanですか? 私のユーティリティクラス。Jarファイルで利用できます。

`public void beforePhase(PhaseEvent イベント) { if(PhaseId.RENDER_RESPONSE.equals(event.getPhaseId())){ SystemListLoaderHelper.populateSelectOneValidValues();

        SystemListLoaderHelper.populateSelectManyCheckboxValidValues();
        FacesContext context = FacesContext.getCurrentInstance();
        ExpressionFactory factory =context.getApplication().getExpressionFactory();
        MethodExpression methodExpression = factory.createMethodExpression(
                context.getELContext(), "#{phaseListenerBean.callModuleSpecificServiceCalls}", 
                Void.class.getClass(),  null);
        methodExpression.invoke(context.getELContext(), null);

// callModuleSpecificServiceCalls(); } }`

4

1 に答える 1

2

FacesコンテキストでBeanを呼び出すことができます。たとえば、Beanが必要な場合は、次を使用できます。

FacesContext facesContext = FacesContext.getCurrentInstance();
Object o = facesContext.getApplication().evaluateExpressionGet(facesContext,
                    "#{phaseListenerBean}", Object.class);

そして、後でリフレクションを使用してメソッドを呼び出すか、次のように、式を使用してメソッドを呼び出すことができます。

FacesContext fc = getContext();
ExpressionFactory factory = getExpressionFactory();
methodExpression = factory.createMethodExpression(
        fc.getELContext(), "#{phaseListenerBean.compListener}", 
                    Void.class, (Class<?>) null);
methodExpression.invoke(fc.getELContext(), null);

「compListener」とユーティリティクラスのコードをいくつか示してください。私の悪い英語でごめんなさい、

乾杯

于 2013-03-13T23:18:37.563 に答える