4

I'm using JSF with the PRG pattern. (use in my navigation rules).

The problem is that the redirect is not done (i.e. a post followed by a get of the same page) when I got validation errors (ex : the mandatory value isn't set by the user).

The scenario is :

  1. user doesn't put the mandatory value and submit the form

  2. validation error occurs and the same view is shown with an error message (no PRG)

  3. the user set the mandatory value and submit ==> GO to the next page (with PRG)

  4. The user click back button => problem because no PRG was done in the step 2. ==> Got a "Document Expired" screen in Firefox

Can anyone help me please?

Thanks in advance.

Stéphane

Stéphane
  • 514
  • 5
  • 16
  • I don't understand your concrete problem. What exactly happens at step 4 then? – BalusC Feb 06 '13 at 12:17
  • Given your [follow-up question](http://stackoverflow.com/questions/14728766/jsf-force-url-rewriting), I believe that your concrete problem is that the input values are redisplayed because you've incorrectly stored them in a session scoped bean instead of a request/view scoped bean. Is my guess correct? Why didn't you tell anywhere in the question what your problem exactly is? You just said "problem" and really nothing else. – BalusC Feb 06 '13 at 12:45
  • I got the "Document Expired" screen from Firefox. I forgot to say that I have a filter that force no-cache... – Stéphane Feb 06 '13 at 12:56
  • @BalusC : I tried you code in http://balusc.blogspot.be/2007/03/post-redirect-get-pattern.html It works great but I'm afraid with the WARNING: JSF1063: WARNING! Setting non-serializable attribute value into HttpSession (key: PostRedirectGetListener.savedViewRoot, value class: javax.faces.component.UIViewRoot). that could be a problem in cluster environnement. – Stéphane Feb 06 '13 at 13:14
  • That phase listener is intented for JSF 1.x and not what you need. – BalusC Feb 06 '13 at 13:37
  • The problem is that I got a "Document expired" screen in Firefox at step 4. – Stéphane Feb 06 '13 at 13:40
  • This problem also is present in plain Servlets: http://stackoverflow.com/questions/15250588/servlet-forward-on-post-validation-failure-and-post-redirect-get – Ryan Mar 27 '13 at 16:59

1 Answers1

2

Just submit the form by ajax. It's a matter of adding

<f:ajax execute="@form" render="@form" />

to the command links and buttons. If you're using <h:message(s)>, then I assume that they are in the very same form, otherwise you need to add their client IDs to the render.

Validation errors while submitting the form by ajax won't generate history.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks, it works. But I would prefer avoid ajax as possible (my company doesn't want to use it for every form submit... (very annoying I know) – Stéphane Feb 06 '13 at 13:50