开发者

Custom component and access to backing bean

开发者 https://www.devze.com 2023-02-15 22:40 出处:网络
Is it possible in JSF2 from a custom component (in method encodeBegin) to access to the FacesContext and managed beans?

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); }

0

精彩评论

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

关注公众号