wood burning stoves 2.0*
The moose likes JSF and the fly likes Firing two actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Firing two actions" Watch "Firing two actions" New topic
Author

Firing two actions

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 152
I would be interested to know how one can fire two actions in separate beans.

Presumably something like:


will not work. So either the action in one bean has to call another, or something can be done with action listeners, or perhaps some JavaScript in the client can be used to fire the second action.

I would be most grateful to know about this.

Christopher Sharp
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

Your best bet general-purpose is to subscribe action listeners.

If the relationship is simple and not subject to change, you can simply chain actions, since an action process is nothing but a method accepting void and returning a string. Just inject the dependent bean into the bean that gets fired first and invoke the second action on the dependent bean.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jerwin Louise Uy
Ranch Hand

Joined: Oct 27, 2007
Posts: 75
Every action has an string that represents a logical outcome in the faces-config.xml. If you do not want to navigate to another resource, then an actionlistener.

My suggestion is to delegate the business logic inside action1 and action2 to POJO classes, which could replace both actions with a single action that delegates processing to POJO classes. Of course, other managed bean can extend this behaviour that would increase reuse of action1 and action2.

Regards.


Uy Jerwin Louise Vergara
Junior Developer / Research and Development at Incuventure Partners Corporation
email: jerwin.uy@incuventure.net
Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 152
Many thanks for the reply, and I might try these.

What I have are three beans, the first is used for login, the second to handle some forms, and the third to handle file uploads. What I need to do on successful submission of the forms is to update the second and third beans. So rather than controlling the second bean directly by an action, I'm now using the login bean as the master bean, and the action is passed to the second bean, where it is processed as before, and the second and third beans are updated.

Whether this will work or not I hope to find out tomorrow.

Christopher Sharp
 
Consider Paul's rocket mass heater.
 
subject: Firing two actions
 
Similar Threads
s:url and javascript onclick submit
Problem with selectOneMenu and valueChangedListener
Struts 1 :- Two Form submission from one jsp using one submit button
Multiaction form or form data outside a form.
Can I have two Action for one Form