开发者

Accessing a controller through a PhaseListener

开发者 https://www.devze.com 2023-04-05 22:29 出处:网络
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#evaluateExpressionGe

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

精彩评论

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