开发者

Accessing a controller through a PhaseListener

I wrote 开发者_开发百科a PhaseListener and would like to know if it is possible to access a controller through it.


You can evaluate an EL expression programmatically by Application#evaluateExpressionGet(). Wrap this in a convenience method like follows:

@SuppressWarnings("unchecked")
public static <T> T findBean(String beanName) {
    FacesContext context = FacesContext.getCurrentInstance();
    return (T) context.getApplication().evaluateExpressionGet(context, "#{" + beanName + "}", Object.class);
}

Use it in your JSF code as follows:

MyBackingBean myManagedBean = JSF.findBean("myManagedBeanName");
// ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜