• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Calling two actionListeners in the same commandButton

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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">
 
Nothing? Or something? Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic