How to solve ViewExpiredException in JSF 1.2

流过昼夜 提交于 2019-12-07 08:30:28

问题


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?


回答1:


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:

  • Our ViewExpiredException tag wiki page
  • javax.faces.application.ViewExpiredException: View could not be restored - for JSF 2.x


来源:https://stackoverflow.com/questions/8315617/how-to-solve-viewexpiredexception-in-jsf-1-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!