Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling two actionListeners in the same commandButton

 
Marcelo Rodriguez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bob Good
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1874
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can create instance for jsf bean and call it. That will work.
 
Bob Good
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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">
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic