Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

execute method

 
Venkat Kanneganti
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can i call other methods in struts Action class with out calling execute() method?i don't want execute() to execute,but for each request for same action one user defined method needs to execute ,is it possible?
Regards
Venkat
 
Joe Ess
Bartender
Posts: 9300
10
Linux Mac OS X Windows
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest that you describe what you are trying to do. While it is technically possible for you to create a new instance of your action class from another action or other Java code and then start calling method on the action, I would generally describe this as bad design. If you have common code that you have to access from multiple actions I would move it out of the action and into a new class...or into your business layer.

- Brent
 
Nick Williamson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To correct the first response: The answer is yes for struts 1 as well, take a look at DispatchAction. Instead of it executing the execute method you pass a parameter to it and it will execute that method as well, which you would define the parameter name in your struts config. So you can do things like myAction.do?parameter=save. When that is executed it will look for a method signature of save(...)

It will throw an error if it cannot find the method, there are ways of taking care of that. It's not the prettiest but it does get the job done if you're stuck with struts 1. I normally used it for CRUD functions and override the unspecified(...) to display the page and list the objects. Then my links on the page will pass parameters in to save, edit, delete, thus calling those methods in my action. If you need an example let me know and I'll copy an example in.
 
Nick Williamson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I decided to post it anyway:

Struts action:



Struts config

 
Venkat Kanneganti
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all who gave response to my doubt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic