File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » JSF
Bookmark "Firing two actions" Watch "Firing two actions" New topic

Firing two actions

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 155
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: 17417

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.

An IDE is no substitute for an Intelligent Developer.
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.


Uy Jerwin Louise Vergara
Junior Developer / Research and Development at Incuventure Partners Corporation
Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 155
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
I agree. Here's the link:
subject: Firing two actions
It's not a secret anymore!