1

elコンテキストまたはアプリケーションコンテキストを介してPhaseListenerの現在のインスタンスを取得する方法はありますか?

4

2 に答える 2

3

<f:phaseListener>次のようなページのタグを使用して、フェーズリスナーをUIViewRootにアタッチできます。

List<PhaseListener> phaseListeners = FacesContext.getCurrentInstance().getViewRoot().getPhaseListeners();

このUIViewRootインスタンスに接続されているPhaseListenerインスタンスのリストを返します。

すべてのグローバルフェーズリスナーをfaces-config.xmlファイルに登録する場合は、次のようにLifeCycleインスタンスから取得できます。

FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);    
LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Iterator<String> lifecycleIds = lifecycleFactory.getLifecycleIds(); 
while (lifecycleIds.hasNext()) { 
    String lifecycleId = lifecycleIds.next(); 
    Lifecycle lifecycle = lifecycleFactory.getLifecycle(lifecycleId);
    PhaseListener[] phaseListeners= lifecycle.getPhaseListeners();
}

ドキュメントUIViewRoot

ドキュメントのライフサイクル

于 2012-07-10T23:18:05.350 に答える
-1

JSF 2.0の現在のPhaseIDは、次の方法で取得できます。

PhaseId currentPhaseId = FacesContext.getCurrentInstance().getCurrentPhaseId();
于 2012-09-13T17:08:05.097 に答える