aspose file tools*
The moose likes Struts and the fly likes Automatically forward to Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Automatically forward to Action" Watch "Automatically forward to Action" New topic
Author

Automatically forward to Action

Sam Gardner
Ranch Hand

Joined: Jul 22, 2008
Posts: 48
Hey Guys -

I have a link set up like so:

"<a href=<s:url action="DemoSrs"/> target="content_frame">continue</a>"

(using the code tags is causing most of the elements to disappear - too many brackets I think)

I'd like to have it automatically triggered - right now it is the only element on a page, and I need it to advance a survey I am setting up.

I've tried using a <jsp:forward> tag using the <s:url...> field as the target, but the page errors out with an "expected quote" error.

Anybody have any quick ideas?

Thanks!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Sam,
How about using a JavaScript function to call it?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Testing the code mentioned above:
Sam Gardner
Ranch Hand

Joined: Jul 22, 2008
Posts: 48
Yeah, I thought of that, but I've been trying to avoid using JavaScript.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Sam Gardner wrote:Yeah, I thought of that, but I've been trying to avoid using JavaScript.

Why? You aren't relying on JavaScript here. If a user has JavaScript turned off, he/she can still click the link by hand.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If you want the link "automatically triggered" then why do you need it at all? Just go to the next page as a result of the action processing/result definition.
Sam Gardner
Ranch Hand

Joined: Jul 22, 2008
Posts: 48
Well, the audience for this particular site needs everything to be as simple as possible, and that particular page is being used in between questions of surveys that have 50 or more questions, so if someone had JavaScript disabled it would be considerably annoying.

This is the "flow" that I need to have working:

1) Survey page, displaying one struts item that uses a dynamically generated list (based on the question number stored in a session variable, so I can display progress and such) in Survey.action

2) Clicking the submit button on the question page triggers Forward.action, which increments the question number and writes the previous answer to the database.

3) I need to refresh the Survey.action page, so that it can display the new question. Right now I have Forward.action dispatch to a second page, and then link back to the Survey.action page.

I want step 3 to happen automatically, but I need the survey page to be refreshed in order to get the new question displayed, and to keep this system flexible for multiple surveys.

If there's no other way that doesn't involve using JavaScript with the link I already am using, I guess I'll have to do that, but I'd really prefer not to. Is there some way I can specify the action definition in struts.xml to forward to an action url instead of just a JSP?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I think I'm completely missing something about what you're saying, because the way I read that you're just submitting a form and redirecting to another page--like any other form processing, normal post-redirect.

As far as redirecting to an action, of course--you can either just put in the full action path to a normal "redirect" result type, or use "redirectAction" and put in only the action name.

You can also use OGNL expressions in the result configuration (whether XML- or annotation-based) if you need to pass something on in the redirect.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Automatically forward to Action