Search code examples
javajsf-2managed-beancustom-component

Custom component and access to backing bean


Is it possible in JSF2 from a custom component (in method encodeBegin) to access to the FacesContext and managed beans?

Thanks you.


Solution

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