Posts Tagged No saved view state

No saved view state

How many of you did already get the following error when working with JSF?
I would be surprised if none of you got it at least once! πŸ˜‰


/web/home.htmlNo saved view state could be found for the view identifier: /web/home.html


Caused by:

javax.faces.application.ViewExpiredException: /web/home.htmlNo saved view state could be found for the view identifier: /web/home.html
	at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(
	at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(
	at org.apache.myfaces.lifecycle.LifecycleImpl.execute(
	at javax.faces.webapp.FacesServlet.service(
	at org.mortbay.jetty.servlet.ServletHolder.handle(
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
	at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(
	at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(
	at org.ajax4jsf.webapp.BaseFilter.handleRequest(
	at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(
	at org.ajax4jsf.webapp.BaseFilter.doFilter(
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(

This very common error happens because your session has timed out. As you probably already know, JSF is storing the view state of your page in session. Obviously, when the session has timed out, it can’t restore the view state and so throws a ViewExpiredException.

The solution for this problem is to add the following lines in your web.xml file:


When this initialization parameter is turned on, it changes ViewHandler.restoreView() to build the view before asking the StateManager for help.

However, if you are using RichFaces, for some reason this is breaking a few Ajax components! πŸ™
To be honest with you, I didn’t investigate in depth why these components don’t work with this parameter set to true.

What I did instead is to make sure the session actually never times out! πŸ˜‰
To do that, I am polling the server every 29 minutes (as my session time out is set to 30 minutes). Obviously, you can poll the server only every 59 minutes if you set your session time out to 60 minutes.

Here is the code I used to poll the server every 29 minutes:

    <a4j:poll id="poll" interval="1740000" limitToList="true" />

Note that the interval attribute is in milliseconds (29 minutes x 60 x 1000 = 1,740,000 milliseconds).

This solution is far from being perfect! Indeed, if, for example, a user doesn’t close his browser during the night, it means that we will have to keep the session opened during hours! 😐
But, as far as I am concerned, it is still better than to throw an exception at the user face. πŸ˜‰

, , , , , , ,