• 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

ActionErrors and redirect = true

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

I am having troubles :-(. I have followed the PRG (post, redirect, get) pattern for my application which works wonderfully. My problem is that the actionerrors that are saved in my action (with saveerrors) are lost when the redirect executes. I understand why this happens (because they are stored in the request, not the session). What I need to know is, what is the best way to work around this problem? I have read a few different ways to work this out such as:
- subclassing Action and overriding the saveErrors method like this:

- saving the errors in the session then reading the from the session in the validate method of the error form that I redirect to.

I'm sure this isnt a new problem and wondering what is the best practice out there and could really use some help.

Thanks guru's.

Yeuker
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest that you not override the saveErrors method of the Action class, but just use it as-is. This method is overloaded with two different signatures: one that accepts a session as a paramaeter and one that accepts a request. Just use the one that accepts a session as a parameter, and your messages will be saved in the session, thereby making them available even after a redirect.
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the thing you need to take care is keeping the session clean. From the code you posted I couldn't make out if you are binding just one exception or more than that. If you actually make use of ActionErrors or ActionMessages then you must clean the error messages session more often (in fact after every request) than overwriting only if it exists.

It's critical as for as I see as in the application I am working, on specific circumstances exception surfaced in wrong pages.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic