aspose file tools
The moose likes Struts and the fly likes can I call an action inside my action? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "can I call an action inside my action?" Watch "can I call an action inside my action?" New topic
Author

can I call an action inside my action?

shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
can I call another action class from another action class?

action path = /search type = com.company.struts.searchaction

action path = /showdetails type = com.company.struts.showdetailaction

searchaction.java

if(condition)
call showdetailaction
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Since an Action class is a regular Java class that has a constructor, there's nothing to prevent you from instantiating an Action class and calling one of its methods from another Action class.

I would consider this to be very bad form, however. If you find yourself needing to do this, it's a good indication that it's time to refactor. Extract the logic that needs to be performed by both actions into a method in either a utility class or a business layer class and call the method from both Action classes.


Merrill
Consultant, Sima Solutions
Joan Horta Tosas
Ranch Hand

Joined: Feb 01, 2007
Posts: 59
You can also "chain" the actions with a forward with a path to the action (with the .do at the end). I've used this some times and it works well for me. Then in that action return ActionFoward to the another action.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: can I call an action inside my action?
 
Similar Threads
Newbie: Struts 1 -> Passing from one struts action to another
Can i call action class getRedirectUrl() method from another class?
Problem with calling IncludeAction
How to call a jsp page from another jsp page in struts
Forwarding to a method in the same DispatchAction class.