Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can I call an action inside my action?

 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joan Horta Tosas
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic