Is it possible in JSF2 from a custom component (in method encodeBegin) to access to the FacesContext and managed beans?
Thanks you.开发者_JAVA技巧
Yes. Even more, the FacesContext
is available as method argument of encodeBegin()
method.
Then, to access managed beans, use Application#evaluateExpressionGet()
.
Bean bean = (Bean) context.getApplication().evaluateExpressionGet(context, "#{beanName}", Bean.class);
public Object getSessionBean(String beanName) {
FacesContext context = FacesContext.getCurrentInstance();
sessMap = context.getExternalContext().getSessionMap();
return sessMap.get(BeanName);
}
精彩评论