• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Firing two actions

 
Christopher Sharp
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christopher Sharp
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic