This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes ActionErrors and redirect = true Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ActionErrors and redirect = true" Watch "ActionErrors and redirect = true" New topic
Author

ActionErrors and redirect = true

Cory Max
Ranch Hand

Joined: Jul 20, 2005
Posts: 83
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


There are only 10 types of people in this world... Those who understand binary and those who don't.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
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.
 
 
subject: ActionErrors and redirect = true