May 13th, 2008, 03:48 PM
Return to previous page from onSubmit
I'm trying to find a good way to return to the calling page after processing a form in a SimpleFormController. For example, I have an edit page called "edit.jsp", and I have an "edit" link on pages a.html, b.html, and x.html. Once the user clicks "Submit" from edit.jsp, I'd like to return the user to whatever page he clicked "edit" from. That is, either a.html, b.html, or x.html.
I've searched the javadocs for HttpServletRequest in the hopes it had something to tell me where the request came from, but have found nothing.
I'm sure there is a simple solution for this, but being new to j2ee and even newer to Spring, I'm stuck in need of a nudge.....
May 13th, 2008, 04:14 PM
I found the partial answer to my question, with this: request.getHeader("Referer"));
However, in my onSubmit, the referer is the current page I'm on. This is no good! Is this is legitimate solution:
1. handleRequest finds the referer and passes it to the view as part of the model map.
2. my form passes that URL back to my controller in a hidden field.
3. My controller redirects to that URL.
I will give that a shot, but is that a "best practice" way to do it? These are questions from a dude with years of fat client experience, and weeks of thin client :-)
Related question, how come "handleRequest" gets called when my submit button is pressed? So the flow is: handleRequest -> show the page, user clicks submit -> handleRequest -> doSubmit
May 13th, 2008, 04:18 PM
Hm.... well it worked so I'm not complaining! :-)
I will say that I'm now 2 for 2 in spending 1+ hours banging my head, then posting, then figuring it out within minutes after posting......
Jun 23rd, 2010, 10:44 AM
This is a good use case. I'd like to use it too. Anyone had a solution?