This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Struts and the fly likes Action without redirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Action without redirect" Watch "Action without redirect" New topic

Action without redirect

Aleksander Braula

Joined: Nov 20, 2009
Posts: 10
I have a problem with making a struts2 action.

I have one action (under a button) that can be invoked from several different places on the site. When the users presses the button I want the action to be invoked but without changing the page and only reloading (with the same get parameters) it to see the new values.

Because the button is in number of different location I cant really determine where the call came from.

Is it possible to do it without multiple entries in the action mapping file ?

At the moment I'm redirecting to a conformation page and there I have a back button with a js "history.back()".
It works but it doesn't reload the page. Just gives the page from cache.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.

[Asking smart questions] [About Bear] [Books by Bear]
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Here's a thought, could you hide an IFRAME on your page (put it in a hidden div) and then when your button is hit, set the src attribute of your IFRAME to the URL for your action. I think this will cause the IFAME to send the action to your server without affecting anything visible on the page. If you need you should be able to access the results of the action from your main page once the responce is returned to the IFRAME. You could probably make a custom tag for your button that will set up the DIV and IFRAME.

Also, I think you can do this kind of thing with ajax, but I've never used it so I'll defer to any one with ajax experience who has a slicker way to do this.

Hope this helps.
David Newton

Joined: Sep 29, 2008
Posts: 12617

I don't understand the usecase. Can't you tie the button to a JavaScript function that sets a request value? Seems much easier than any IFRAME shenanigans.
I agree. Here's the link:
subject: Action without redirect
It's not a secret anymore!