10

In our JSF2 project on JBoss 7.1.1, we define a session timeout in the web.xml and it works just fine.

However, sometimes we're getting view expiration, leading to errors like this one even if the session is still alive:

javax.faces.application.ViewExpiredException: viewId:/... - View /... could 
not be restored.

Where can we set the view timeout, like we did for sessions? Or is the view expiration caused by something else?

Xavier Portebois
  • 3,354
  • 6
  • 33
  • 53

1 Answers1

15

Another cause of ViewExpiredException is that too many logical views are been created in the session. The default limit is JSF implementation specific and every synchronous GET request on a particular view basically creates a new view. So, for example, when you use Mojarra (which has a default limit of 15) and start a browser session and open the same view in 16 different tabs and then submit a form in the 1st one, then you may get this exception as well. The limit is configureable with a JSF implementation specific context parameter, which is com.sun.faces.numberOfLogicalViews for Mojarra and org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION in MyFaces (defaults to 20).

This is however a very rare real world problem. If your webapp is really designed to be used this way (e.g. a social/community site which invites to being opened in multiple tabs, such as discussion forum or Q&A), then you might consider using client side state saving instead.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hm, seems good, thanks. But anyway, is there a view expiration timeout and if there is, how is its lifespan defined? – Xavier Portebois Sep 25 '12 at 06:59
  • 3
    There's no timeout other than the session timeout. There's as answered however the "maximum views" setting which you could set higher up. A view is created when you request a view for the first time by a GET request and lives as long as you postbacks to it while not navigating to a different view (as in ajax postbacks and return null/void actions). – BalusC Sep 25 '12 at 10:53