Is there a way to specify a managed bean used in EL at runtime and not design time? E.g.
actionListener="#{myBean.method}" such that myBean part can have different values depending on the JSF page the code is invoked from (on condition that any object used instead of myBean is derived from a common parent implementing the “method”).
Is there a way to specify a managed bean used in EL at runtime
Share
If you know the bean scope beforehand and the bean is already created beforehand, then yes, it’s possible using the following syntax:
where
#{requestScope}represents the request scope map (same maps are available for view, session and application scopes) and#{beanName}represents the variable holding the managed bean name.If you don’t know the bean scope beforehand and/or when the bean isn’t created beforehand, then you’d need to create an utility EL function which does an
Application#evaluateExpressionGet(), so that it can be used something like as follows: