RE: using redirecting forwards after failed validation
I did the following to get around the drawback with RequestProcessor that you pointed out: 1) keep the ActionErrors as a request attribute 2) set the validate parameter to false for the ActionMapping 3) add code like the following to the search action itself: errs = form.validate(); if (!errs.isEmpty()) { saveErrors(errs); return mapping.getInput(); } I've also seen a solution like this floating around the list in the last few days. A note: this solution will forward to your input page, not redirect. I'm not entirely sure from your message on why you'd like to redirect to the input. It sounds like you're not set on it, so maybe a forward like the above will do. B -Original Message- From: Par Winzell [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 17, 2003 10:41 AM To: [EMAIL PROTECTED] Subject: using redirecting forwards after failed validation Hello everyone -- this is my first post. I'm hoping you can help with a problem. I've seen bits and pieces of this question asked, but not entirely... Here's my problem: When the user enters data into a 'enter search parameters' form and validation fails, I don't want the URL to proceed to the 'perform the search' action. This means I have to use redirecting forwards for the 'input' attribute. However, with redirects... if I understand correctly... it's not good enough to store validation errors in the request attributes. They need to go into session scope. My problem is figuring out where this should happen. Experimentally, I now mask validate(), which basically does errors = super.validate(); request.getSession().setAttribute(ERROR_KEY, errors); return errors; but this feels rather nasty to me; validate() is supposed to return values, not cause side-effects... right? The problem is that RequestProcessor.java is entirely atomic all the way from calling validate() to performing the redirect. Is there some other way to do this that I'm missing? ... or should I not be doing what I'm doing? Is there some other way to get redirection to work, with the validator framework? Appreciate any help -- Par Winzell Madison, WI - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: using redirecting forwards after failed validation
Barett, 1) keep the ActionErrors as a request attribute 2) set the validate parameter to false for the ActionMapping 3) add code like the following to the search action itself: errs = form.validate(); if (!errs.isEmpty()) { saveErrors(errs); return mapping.getInput(); } This seems like forcing a flow that's supposed to be the framework's supposed to deliver... but clearly it's very similar to what the RequestProcessor already does, so it sounds like an acceptable compromise. A note: this solution will forward to your input page, not redirect. I'm not entirely sure from your message on why you'd like to redirect to the input. It sounds like you're not set on it, so maybe a forward like the above will do. If the user's URL reads /gui.do when she first enters her search data, and validation fails, then I believe the URL should still read /gui.do for the second attempt, rather than /executesearch.do or whatnot. That does require a redirect, right? Anyway, your solution should work equally well while storing the errors in the session context. Many thanks! Zell - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: using redirecting forwards after failed validation
You are correct. Your decision to put the errors in the session is necessary if you want the URL to read that way. My understanding is that all request attributes will vanish if you redirect. Most notably including the ActionErrors that the thread was all about! :) I have long since given up trying to control what the URL line reads, in favor of preserving a slim session. But this is one of the many tradeoffs we all make with Struts. Also a small problem with the code that I originally submitted that would make this more obvious: - saveErrors(errs); + saveErrors(request, errs); Thanks for the comments. B -Original Message- From: Par Winzell [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 17, 2003 3:36 PM To: Struts Users Mailing List Cc: 'Par Winzell' Subject: RE: using redirecting forwards after failed validation Barett, 1) keep the ActionErrors as a request attribute 2) set the validate parameter to false for the ActionMapping 3) add code like the following to the search action itself: errs = form.validate(); if (!errs.isEmpty()) { saveErrors(errs); return mapping.getInput(); } This seems like forcing a flow that's supposed to be the framework's supposed to deliver... but clearly it's very similar to what the RequestProcessor already does, so it sounds like an acceptable compromise. A note: this solution will forward to your input page, not redirect. I'm not entirely sure from your message on why you'd like to redirect to the input. It sounds like you're not set on it, so maybe a forward like the above will do. If the user's URL reads /gui.do when she first enters her search data, and validation fails, then I believe the URL should still read /gui.do for the second attempt, rather than /executesearch.do or whatnot. That does require a redirect, right? Anyway, your solution should work equally well while storing the errors in the session context. Many thanks! Zell - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]