• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to return to the last page in failure

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Background:
The application I am developing is Struts based and consists of nested jsps and tiles.

Problem:
Suppose at certain point user will commit his transactions. Some of them will fail. The question is how to redirect the user back to the last page before he committed?

Constraints:
1) Client side caching/refreshing such as JavaScript history object is not allowed. Checking of double submssions would fail you.
2) Technique such as caching the current URL in the HTTPRequest for the "return URL" session before committing a transaction is not going to work either as we simply don't know which one is the "current URL" as a page is an aggregated results of multiple jsps and tiles.

Would be very much appreciate if hints can be provided.

Thanks in advance,
Jon
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you are using Struts, if your action defines a forward for where to go on an error, and your action handler did the work to call the database, then the handler would know when the transaction has failed.
Then inside the handler, for the block of code where the failure is acknowledged, have the action forward to the error page, which could be the same page, or the page you used to be.
You could also set some ActionErrors to be displayed

Below is an example of what I mean.
Consider you have a 2 page form, where the flow goes from (home) -> page1 -> page2. and the transaction is committed on page 2.

the struts-config.xml may look like:

<action path="page1" type="edit.Pagae1" name="page1Form" input="tiles.editForm1" scope="session">
<forward name="home" path="tiles.editForm1" />
<forward name="invalid" path="tiles.editForm1" />
<forward name="cancel" path="home.do" />
<forward name="next" path="page2.do" />
</action>


<action path="page2" type="edit.Page2" name="page2Form" input="tiles.editForm2" scope="session">
<forward name="home" path="tiles.editForm2" />
<forward name="invalid" path="tiles.editForm2" />
<forward name="cancel" path="home.do" />
<forward name="back" path="page1.do"/>
<forward name="error" path="page1.do"/>
<forward name="finish" path="home.do" />
</action>

I guess the forward for "error" in page2 could go to tiles.editForm1 instead of invoking the struts form / handler for page1.do again, or could go to some other tiles based error page.



Then, in the execute() within the handler for Page2:

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

try {
// do save of things here, that may fail.
}
catch (SomeFailureException ex) {
// it failed, we want to go back to the first screen (previous)
// roll back here..
// redirect to the forward we call "error" in page2 action.
return mapping.findForward(error).
}

// things worked ok,

return mapping.findForward(finish);
}
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you're writing this with Struts, your best answers will probably come from fellow Struts users.

Moving to the Struts forum.
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic