aspose file tools*
The moose likes Struts and the fly likes execute method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "execute method" Watch "execute method" New topic
Author

execute method

Venkat Kanneganti
Ranch Hand

Joined: Nov 30, 2007
Posts: 43
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

Joined: Oct 29, 2001
Posts: 8964
    
    9

Struts 1: the answer is 'no'.
Struts 2: the answer is 'yes'


[How To Ask Questions On JavaRanch]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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

Joined: Jan 06, 2007
Posts: 73
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

Joined: Jan 06, 2007
Posts: 73
I decided to post it anyway:

Struts action:



Struts config

Venkat Kanneganti
Ranch Hand

Joined: Nov 30, 2007
Posts: 43
Thank you for all who gave response to my doubt
 
 
subject: execute method