4

I have an application using JSF1.2 + Richfaces 3.3.3 Final, MyFaces 1.2.7, Spring + Hibernate and I get the below exception everytime when I clear the cache and cookies of the browser and login again to my application.

javax.faces.application.ViewExpiredException - /app/project/index.jsf
No saved view state could be found for the view identifier: /app/project/index.jsf

Can anyone let me know how to solve above exception?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kapil Nimje
  • 81
  • 1
  • 1
  • 7

1 Answers1

9

You can solve it by setting the state saving method to client instead of server so that views are stored (in serialized form, of course) in a hidden input field of the POST form, instead of in the session in the server side (which is in turn to be referenced by JSESSIONID cookie; so all views will basically get lost when you delete the session cookie or when the session expires). You can do that by adding the following context parameter to the web.xml:

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>

If the above is not an option for some reason, then best what you could do is to handle it gently as an error page in web.xml as follows:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/errors/sessionexpired.jsf</location>
</error-page>

This does not solve the exception, but it at least offers you the opportunity to tell in the error page the enduser about the problem and what actions the enduser has to take. You could even let the error page point to the login page and conditionally render some message about why the enduser is facing the login page again.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks Balus for your reply, but we have already used this in our application, but we are using server incase of client method. So if we change this to client method, will that cause any harm to my application? javax.faces.STATE_SAVING_METHOD client – Kapil Nimje Nov 30 '11 at 17:27
  • This won't cause any harm to your application. Only the bandwidth usage will increase a little (but not that much if you turn on GZIP compression on the server; you'll even win more if you haven't already configured the server to use GZIP compression). – BalusC Nov 30 '11 at 17:34
  • Also i have tried below approach as well, but i my case once the exception is raised its not redirected to sessionExpired page, instead its redirected to login page bydefault. \n javax.faces.application.ViewExpiredException /errors/sessionexpired.jsf . – Kapil Nimje Nov 30 '11 at 17:36
  • Then you've another `` in `web.xml` which has a more global `` which took precedence over the `ServletException`. You'd need to create a `Filter` which catches a `ServletException` and rethrows its root cause instead. See also http://stackoverflow.com/questions/3206922/issue-with-jsf-viewexpiredexception-and-multiple-error-page-tag-definitions-in-w/3208055#3208055 – BalusC Nov 30 '11 at 17:37