首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSF2 --从托管bean获取PhaseListener实例

JSF2 --从托管bean获取PhaseListener实例
EN

Stack Overflow用户
提问于 2012-07-11 04:57:28
回答 2查看 1.1K关注 0票数 1

有没有办法通过el上下文或应用程序上下文获取PhaseListener的当前实例?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-11 07:18:05

您可以在如下所示的页面上使用<f:phaseListener>标记将阶段侦听器附加到UIViewRoot:

代码语言:javascript
复制
List<PhaseListener> phaseListeners = FacesContext.getCurrentInstance().getViewRoot().getPhaseListeners();

它返回附加到此UIViewRoot实例的PhaseListener实例的列表。

如果您想要在faces-config.xml文件中注册所有全局阶段侦听器,您可以像这样从LifeCycle实例中获取它们:

代码语言:javascript
复制
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();
}

Documentation UIViewRoot

Documentation LifeCycle

票数 3
EN

Stack Overflow用户

发布于 2012-09-14 01:08:05

您可以使用以下命令获取JSF2.0中的最新PhaseID:

代码语言:javascript
复制
PhaseId currentPhaseId = FacesContext.getCurrentInstance().getCurrentPhaseId();
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11421826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档