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

Reply via email to