| Author |
Calling two actionListeners in the same commandButton
|
Marcelo Rodriguez
Greenhorn
Joined: Feb 28, 2008
Posts: 6
|
|
|
I have a method in a managed bean that store data from a form and i also have a method in another managed bean that fill a SelectOneMenu with SelectItems taken from DAO, i have to call these two methods in the same commando button. Any ideas? Can I call a method of a managed bean that not have been instanciated?
|
- The powerfull men can destroy one rose or two, they can even destroy the Spring (and Struts), but they will never defeat Java Server Faces (Only Tapestry can do that...) - 'Ctrl+C, Ctrl+V of Che Guevara Quote, with cH4n6Es'
|
 |
Bob Good
Ranch Hand
Joined: Jan 09, 2008
Posts: 86
|
|
You can ask for the managed bean to be instantiated if it is not already yet like this: After that you could have one action method call the other action method yourBean.doSecondAction();
|
 |
Bob Good
Ranch Hand
Joined: Jan 09, 2008
Posts: 86
|
|
|
Another option is you might use both an action listener and an action method. The action listener (that does not navigate) is called before the action method (which may or may not navigate).
|
 |
Krishna Srinivasan
Ranch Hand
Joined: Jul 28, 2003
Posts: 1803
|
|
|
Yes, you can create instance for jsf bean and call it. That will work.
|
Krishna Srinivasan
OCAJP Mock Questions
|
 |
Bob Good
Ranch Hand
Joined: Jan 09, 2008
Posts: 86
|
|
You can also define a second actionListener on the button like this: <f:actionListener type="yourApp.Listener"> This would be defining an action listener class (in addition to the action listener backing bean method defined on the commandButton). In fact you can define as many listeners as you want, which fits quite well with the Observer design pattern. You can also define multiple value change listeners in a similar fashion: <f:valueChangeListener type="yourApp.ChangeListener">
|
 |
 |
|
|
subject: Calling two actionListeners in the same commandButton
|
|
|