Is it possible to invoke more than one listener method using a single command component? For example,
A view scoped bean:
@ManagedBean
@ViewScoped
pu
Use <f:actionListener binding>:
<h:commandButton value="Action">
<f:actionListener binding="#{viewScopedBean.action()}"/>
<f:actionListener binding="#{sessionScopedBean.action()}"/>
</h:commandButton />
Note the importance of the parentheses in EL. Omitting them would in this particular example otherwise throw a confusing javax.el.PropertyNotFoundException: Property 'action' not found on type com.example.ViewScopedBean
, because it's by default interpreted as a value expression. Adding parentheses makes it a method expression. See also Why am I able to bind <f:actionListener> to an arbitrary method if it's not supported by JSF?
You could even add an actionListener
and/or an action
method to the component the usual way, which is invoked later on. What it has to be unique is the action
method, which decides the outcome for the processing.
Anyway, keep in mind the listeners are always executed before the action and considered a "warming-up" for it. Your best is to perform the whole logic in the action method, even if you need to do bean injections.
See also: