struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Lindholm <greg.lindh...@gmail.com>
Subject Re: PRG pattern question
Date Wed, 26 May 2010 14:42:01 GMT
I don't believe there is any canned "best practice" solution for this issue.
My apps do the same thing; on a successful post I redirect to a get,
on a validation error they simply forward back to the jsp so as to
preserve the input data.

It is possible to manually include all your form fields data as
parameters on the redirect but that is very tedious and error prone
and on large forms you may hit url size limitations.

For me I've just accepted that on a validation fail the back button
will be un-friendly.

If you want to take the route of passing all your fields back on the
redirect when validation fails you could probably write a custom
result type that would automatically append all the request parameters
to the redirect url.  I don't think this would be too hard to write.

Your only other option would be to stuff the data into the session and
then pull in out on the next get.  I would not recommend this
approach, it appears to me to be very error prone as there is no
guarantee that the next request will be the one that wants the data or
that the request will ever happen. You could end up filling up the
session with data that never get retrieved. Just seems like a poor
design.


On Wed, May 26, 2010 at 8:45 AM, szerintedmi <szerintedmi@gmail.com> wrote:
> Hi Everybody,
>
> I would like to ask some advice implementing PRG pattern with struts2 (using
> 2.0.14).
>
> I can easily handle a normal scenario :
> 1.GET showItem.action?itemId=1
>    result: showItem.jsp
> 2. POST saveItem.action
>   result: redirect-action: success?itemId=1
> 3. GET success?itemId =1
>  result: success.jsp
>
> Browser back works perfectly with this workflow.
>
> However if there is a form error at step 2.:
> 1. GET showItem.action?itemId=1
>  result: showItem.jsp
> 2.1 POST saveItem.action
>   result: showItem.jsp (with field/action errors)
> 2.2 POST saveItem.action (user fixed errors on form)
>  result: redirect-action: success?itemId=1
> 3. GET success?itemId=1
>  result: success.jsp
>
> In this scenario if the user press back after the 3rd step he gets a page
> with saveItem.action url (without params) and with a re-submit browser
> alert.
>
> If a form validation error happens I could use a redirect-action result to
> showItem.action at step 2.1.
> But that way I'm loosing all the posted form data and the data field/action
> errors.
>
> Alternativelly I could use the same action to show and save, that way url
> would be showItem after 2.1 but still without url params. I could hack url
> query string to the reponse but still have re-submit alerts from browser
> after user press back button because that was a result of a post.
>
> What is the best practice to handle form errors with struts if I want to
> implement Post-Redirect-Get pattern?
>
> Thanks,
>
> Peter
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message