File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts2: From One Action to another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2: From One Action to another" Watch "Struts2: From One Action to another" New topic
Author

Struts2: From One Action to another

Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
Hi y'all!

What's the trick to calling one action from another action without using redirect? e.g.

Here's my struts.xml file:


Thanks.

Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
BTW..forgot to add,... I'm able to call/execute 'First' but never gets to 'Second'.

Thanks again
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What do you mean, "calling one action from another"? What specifically are you trying to do? There's no reason it would magically "continue" to another action.
Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
David Newton wrote:What do you mean, "calling one action from another"? What specifically are you trying to do?


I'm trying to make action class First execute, return 'success', and then make action Second run without doing a "redirect". So far the only way I am able to run First and then Second is if I explicitly use result type="redirect" which I do not want, e.g.




David Newton wrote:There's no reason it would magically "continue" to another action.





Anyways, by not explicitly specifying a result type I am expecting a "dispatcher" result type as my default (which acts as a forward in lieu of redirect?) because my struts xml extends struts-default.


Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Hi,
Are you aware of action chaining in struts2? This URL should help you.

Ananth Chellathurai [Walk on software]
Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
Ananth Chellathurai wrote:Hi,
Are you aware of action chaining in struts2? This URL should help you.


Ananth, that's exactly what I was looking for. Thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Action chaining is almost always never the best answer (or even a good one). It leads to difficult-to-maintain applications.
Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
David Newton wrote:Action chaining is almost always never the best answer (or even a good one). It leads to difficult-to-maintain applications.


Why is that? So what's the best or good answer? Am I back to making dispatcher work and is that a better approach? If it is, I guess I'm back to my first question...what's the trick to making this work? I can get it to forward to a servlet but not for an action. Forwarding to an action results in a '404' error.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Forwarding?

You still haven't said precisely what you're trying to do.
Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
David Newton wrote:Forwarding?

You still haven't said precisely what you're trying to do.


geesh, thanks anyway!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I do not understand your response.

If I don't know exactly what you're trying to accomplish, how could I possibly give you advice about cleaner ways to accomplish it? Example:

You: I am action chaining to set up some variables I need available in the JSP.
Me: Have you considered implementing Preparable, or using the <s:action> tag (with the caveat that the <s:action> tag has some subtle "gotchas")?

But I'd really rather not spend my time guessing what your use case is or specific needs are when you can just tell me and make the process much more efficient. But if you're not willing or able to do so, that's fine too; I'm okay with that.
Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
I see...ok, let me try this again tonight and will provide a much better detail. I have to change gears and work on something else right now. Thanks Dave.
 
Consider Paul's rocket mass heater.
 
subject: Struts2: From One Action to another