This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
There are only 10 types of people in this world... Those who understand binary and those who don't.
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.
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.