Preventing ViewExpiredException in JSF

When our page is idle for x amount of time the view will expire and throw javax.faces.application.ViewExpiredException to prevent this from happening
one solution is to create CustomViewHandler that extends ViewHandler
and override restoreView method all the other methods are being delegated to the Parent

import java.io.IOException;
import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
 
public class CustomViewHandler extends ViewHandler {
	private ViewHandler parent;
 
	public CustomViewHandler(ViewHandler parent) {
		//System.out.println("CustomViewHandler.CustomViewHandler():Parent View Handler:"+parent.getClass());
		this.parent = parent;
	}
 
    @Override public UIViewRoot restoreView(FacesContext facesContext, String viewId) {
	/**
	 * {@link javax.faces.application.ViewExpiredException}. This happens only  when we try to logout from timed out pages.
	 */
	UIViewRoot root =null; 
	root = parent.restoreView(facesContext, viewId);
	if(root == null) {			
		root = createView(facesContext, viewId);
	}
	return root;
 }
 
 @Override
	public Locale calculateLocale(FacesContext facesContext) {
		return parent.calculateLocale(facesContext);
	}
 
	@Override
	public String calculateRenderKitId(FacesContext facesContext) {
		String renderKitId = parent.calculateRenderKitId(facesContext);
		//System.out.println("CustomViewHandler.calculateRenderKitId():RenderKitId: "+renderKitId);
		return renderKitId;
	}
 
	@Override
	public UIViewRoot createView(FacesContext facesContext, String viewId) {
		return parent.createView(facesContext, viewId);
	}
 
 
    @Override
	public String getActionURL(FacesContext facesContext, String actionId) {
		return parent.getActionURL(facesContext, actionId);
	}
 
	@Override
	public String getResourceURL(FacesContext facesContext, String resId) {
		return parent.getResourceURL(facesContext, resId);
	}
 
	@Override
	public void renderView(FacesContext facesContext, UIViewRoot viewId) throws IOException, FacesException {
		parent.renderView(facesContext, viewId);
 
	}
 
	@Override
	public void writeState(FacesContext facesContext) throws IOException {
		parent.writeState(facesContext);
	}
 
	public ViewHandler getParent() {
		return parent;
	}
 
}

Then you need to add it to your faces-config.xml

<view-handler>com.demo.CustomViewHandler</view-handler>

This will prevent you from getting ViewExpiredException’s

37 thoughts on “Preventing ViewExpiredException in JSF”

  1. Hi, I am trying to implement this example but not sure where does the object ‘parent’ come from. Please help me.

    Regards,
    Kashif

    1. Parent comes from the ViewHandler constructor, also there are other methods that can be overwritten if you like.

      private ViewHandler parent;

      public CustomViewHandler(ViewHandler parent) {
      //System.out.println("CustomViewHandler.CustomViewHandler():Parent View Handler:"+parent.getClass());
      this.parent = parent;
      }

      Hope this helps, also I will update the post with this.

  2. Hi I tried this example and I get failure. It is due to the spread of ViewHanler you add other methods that do not what to do with them. In asking that page shows me what I’m doing gives me an error java.lang.NullPointerException: renderKitId

    I’m a little awkward and not what you have to do. Please help.

  3. I have updated the example with the other overwritten methods that should fix your problem.
    If you still having issues post your code for your Custom ViewHandler

  4. If you’re using Facelets you can extend FaceletViewHandler and just have the restoreView() method. In my case I also return an error/information page if root == null. I think it’s more user friendly. Here’s the code:

    public class MyFaceletViewHandler extends FaceletViewHandler {
     
        public MyFaceletViewHandler(ViewHandler parent) {
            super(parent);
        }
     
        @Override
        public UIViewRoot restoreView(FacesContext facesContext, String viewId) {
            UIViewRoot root = super.restoreView(facesContext, viewId);
            // do not allow ViewExpiredException
            if (root == null) {
                root = createView(facesContext, "/viewExpired.xhtml");
                facesContext.renderResponse();
            }
            return root;
        }
     
    }
  5. Thanks for the solution. But I still do have some problems getting around my basic issue.
    I have a secured application (Spring security), with a simple login form. I can happen fairly often that the user opens the login page and leaves the browser open without performing a login.
    The session times out and when the user tries to login he would get a ViewExpiredException.
    Displaying a session-time-out-page makes no sense, the user was at the start page and overriding the ViewExpiredException-behaviour for this single, simple issue seems like a dangerous overkill for me.
    Is there any other way telling JSF this is the start page, we do not need a stored view for this??? I have read numerous articles about this and it has been bugging me for nearly a year(!) that you need to make fairly big changes in the JSF-ecosystem for imho a very, very common problem.
    Where am I wrong?

    1. You might want to use

       
          javax.faces.application.ViewExpiredException
          /sessionExpired.jsf

      in you faces-config.xml it might work for you. There is also a way of defining on how to catch errors in web.xml

  6. Sébastien Tromp

    Hello,

    Thanks for this article. If I understood well, if a ViewExpiredException would be thrown, it is simply eaten and the page is rendered as it would have been otherwise (like would be the case for instance with a manual refresh of the page from the user).

    However, I can’t seem to get it work. Instead of the usual “ViewExpiredException”, I now have a simple error page saying “the required resource () could not be found”.

    I am using JSF 2.0 on Tomcat 7.0. No trace or message in the logs.

    Would you have any idea as to what is causing this?

    Thanks,
    Sébastien

    1. It is possible that you are handling this via configuration in your web.xml can you, post it here or email it to me at gregbugaj @@@ yahoo.com

      Look for something like

      500
      /500error.html

  7. Sébastien Tromp

    Hello,

    I cannot copy the content of the files here (“comment looks a bit spammy”), so I have sent them to you via e-mail.

    The ViewHandler is an exact copy of your example.

    And when I try to access other pages in the site, I get an error like
    /pages/page.xhtml Not Found in ExternalContext as a Resource

    Thanks for your help 🙂

  8. Going to try this Greg, I will let you know if it works, Thank you! We are having Trinidad page working on portlet weblogic server, the date picker refreshes the pages and that in turn causes View Expiry exception, so I am trying your fix to solve our problem. 🙂

  9. Thank you very much for the solution offerd by you in preventing ViewExpiredException in JSF.WE are using Richfaces 4 based JSF 2.0 GUI on JBOSS 6 for our Spring secured Project.

    The problem I am facing is that When a user page is idle for an X amount of time the session times out and the user will be Ideally directed to the login page but when the user tries to login instead of the usual “ViewExpiredException”, I now have a error page saying “HTTP 500 – The server encountered an internal error () that prevented it from fulfilling this request”.(Other pages also cannot be accessed once this error is thrown.)

    Error screen shot – https://picasaweb.google.com/111228036846988065850/ViewExpiredExceptionInJSF

    The ViewHandler is an exact copy of your example. except the fact that I enabled the system out’s for debugging.

    The below configuration was added to the end of the faces-config.xml


    com.xxxxx.jsf.listener.CustomViewHandler

    (The Stack trace thrown refers to a line in the restoreView method which I have highlighted in the screenshot above.)

    @Override public UIViewRoot restoreView(FacesContext facesContext, String viewId) {
    …..
    root = parent.restoreView(facesContext, viewId);(The Stack trace makes a reference to this point)

    Would you have any lead as to what is causing this glitch in the project?

    Thank You in advance 🙂

  10. More information related to CustomViewHandler class encountered…

    I started the given class with system out messages enabled.(Highlighted with **** )

    The java IDE console displays the following messages. The error is generated when a user attempts to login to the system.

    15:50:05,541 INFO [STDOUT] CustomViewHandler.CustomViewHandler():Parent ViewHandler: *** class org.richfaces.application.GlobalResourcesViewHandler
    ……

    15:50:13,210 INFO [org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.0.0.Final “Neo”] Started in 3m:13s:314ms
    15:50:13,792 INFO [STDOUT] CustomViewHandler.calculateRenderKitId():RenderKitId: *** HTML_BASIC
    15:50:13,795 INFO [STDOUT] CustomViewHandler.calculateRenderKitId():RenderKitId: *** HTML_BASIC
    15:50:14,456 INFO [STDOUT] CustomViewHandler.calculateRenderKitId():RenderKitId: *** HTML_BASIC
    15:50:14,456 INFO [STDOUT] CustomViewHandler.calculateRenderKitId():RenderKitId: *** HTML_BASIC
    15:50:30,330 INFO [STDOUT] CustomViewHandler.calculateRenderKitId():RenderKitId: *** HTML_BASIC
    15:50:30,330 INFO [STDOUT] facesContext *** com.sun.faces.context.FacesContextImpl@b80ce5
    15:50:30,330 INFO [STDOUT] viewId **** /login.xhtml
    15:50:30,330 INFO [STDOUT] CustomViewHandler.calculateRenderKitId():RenderKitId: *** HTML_BASIC

    15:50:30,340 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/ustocktrade].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.RangeCheck(Unknown Source) [:1.6.0_25]
    at java.util.ArrayList.get(Unknown Source) [:1.6.0_25]
    at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:161) [:2.0.3-FCS]
    at javax.faces.component.UIInput.restoreState(UIInput.java:1381) [:2.0.3-FCS]
    at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1203) [:2.0.3-FCS]
    at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1218) [:2.0.3-FCS]
    at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1218) [:2.0.3-FCS]
    at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1218) [:2.0.3-FCS]
    at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1218) [:2.0.3-FCS]
    at javax.faces.component.UIViewRoot.processRestoreState(UIViewRoot.java:866) [:2.0.3-FCS]
    at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:197) [:2.0.3-FCS]
    at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:119) [:2.0.3-FCS]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:438) [:2.0.3-FCS]
    at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:144) [:2.0.3-FCS]
    at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:284) [:2.0.3-FCS]
    at com.ustocktrade.jsf.listener.CustomViewHandler.restoreView(CustomViewHandler.java:32) [:]
    // ************ (refers to line root = parent.restoreView(facesContext, viewId);
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:182) [:2.0.3-FCS]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) [:2.0.3-FCS]
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:107) [:2.0.3-FCS]
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) [:2.0.3-FCS]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) [:2.0.3-FCS]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343) [:]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) [:]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:109) [:]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355) [:]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149) [:]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) [:3.0.0.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) [:3.0.0.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final]
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
    at java.lang.Thread.run(Unknown Source) [:1.6.0_25]

    But reverting back to the standard ViewHandler seems to work fine. Could it be a Spring Security related issue?

    Thanks for your help 🙂

  11. Hi Greg,

    We are getting same exception but session is never timed out. Occurs only few times and it is also very hard to reproduce this. Please check below line from logs.

    2011-12-12 15:10:06,217 FINE [javax.enterprise.resource.webcontainer.jsf.application] (ajp-0.0.0.0-8009-1) viewId after appending the context suffix view.xhtml
    2011-12-12 15:10:06,217 FINE [javax.enterprise.resource.webcontainer.jsf.application] (ajp-0.0.0.0-8009-1) Begin restoring view in session for viewId view.xhtml
    2011-12-12 15:10:06,217 FINE [javax.enterprise.resource.webcontainer.jsf.application] (ajp-0.0.0.0-8009-1) Session Available, but View State does not exist for viewId: view.xhtml

    Can you please guide us what steps to take?

  12. I also needed to add

    @Override
    public ViewDeclarationLanguage getViewDeclarationLanguage(
    FacesContext context, String viewId) {

    return parent.getViewDeclarationLanguage(context, viewId);

    }

    without this I was getting nullPointer Ex.
    because javax.faces.application.ViewHandler provides such
    implementation:

    public ViewDeclarationLanguage getViewDeclarationLanguage(FacesContext context,
    String viewId) {

    return null;

    }
    🙂

    I am using tomcat 7 jsf 2.0 (Mojarra 2.1.2 (FCS 20110610))

  13. Hi Greg,

    Thank you very much for the example.

    Whenever session expires i want to redirect to the SessionExpiry.xhtml. This is working fine for the facelets components(h:commandButton) but not with the richfaces component(a4j:commandButton).

    Could you plz help me in this regard.

    Thank in advance

  14. Greg, thank you for your article and thanks Alex for his advice on extending FaceletViewHandler. It helped me to properly handle ViewExpiredException. (Oh, and hello from 2012.;))

  15. I have a tree component using Jsf 1.2 on click of link some times i am getting ViewExpiredException.
    Can any body help me on this.

    [9/25/12 14:55:12:802 IST] 00000029 lifecycle E JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: “”) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@4b294b29]
    [9/25/12 14:55:12:818 IST] 00000029 lifecycle W JSF1053: (Listener: com.acs.manager.ManagedBeanRestoreStatePhaseListener.afterPhase(), Phase ID: RESTORE_VIEW 1, View ID: “”) Exception thrown during phase-listener execution: java.lang.NullPointerException
    [9/25/12 14:55:12:818 IST] 00000029 lifecycle W com.acs.manager.ManagedBeanRestoreStatePhaseListener.afterPhase(ManagedBeanRestoreStatePhaseListener.java:23)

    9/25/12 14:55:12:834 IST] 00000029 PortletContai E com.ibm.ws.portletcontainer.PortletContainerImpl doAction EJPPC0101E: Error occurred during portlet action processing
    javax.portlet.PortletException: viewId:/jsp/benefitplannavigator/benefitPlanCoverage.jsp – View /jsp/benefitplannavigator/benefitPlanCoverage.jsp could not be restored.
    at com.ibm.faces.portlet.FacesPortlet.processAction(FacesPortlet.java:199)
    at com.acs.enterprise.common.program.benefitadministration.view.portlet.BenefitPlanPortlet.processAction(BenefitPlanPortlet.java:191)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletFilterChainImpl.doFilter(PortletFilterChainImpl.java:77)
    at com.ibm.wps.propertybroker.standard.filter.PropertyBrokerActionFilter.doFilter(PropertyBrokerActionFilter.java:712)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletFilterChainImpl.doFilter(PortletFilterChainImpl.java:69)
    at com.ibm.wps.propertybroker.standard.filter.C2APortletFilter.doFilter(C2APortletFilter.java:166)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletFilterChainImpl.doFilter(PortletFilterChainImpl.java:69)
    at com.ibm.wps.engine.dpr.portlet.impl.ProcessActionMemoFilter.doFilter(ProcessActionMemoFilter.java:88)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletFilterChainImpl.doFilter(PortletFilterChainImpl.java:69)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServlet.doDispatch(PortletServlet.java:527)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:114)
    at com.ibm.isclite.container.collaborator.PortletServletCollaborator.doAction(PortletServletCollaborator.java:59)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:101)
    at com.ibm.ws.portletcontainer.rrd.RRDServerPortletServletCollaborator.doAction(RRDServerPortletServletCollaborator.java:117)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:101)
    at com.ibm.ws.portletcontainer.cache.CacheCollaborator.doAction(CacheCollaborator.java:84)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:101)
    at com.ibm.wps.pe.pc.waspc.core.impl.PortletServletCollaboratorImpl.doAction(PortletServletCollaboratorImpl.java:146)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:101)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServlet.doDispatch(PortletServlet.java:301)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:82)
    at com.ibm.isclite.container.collaborator.PortletServletCollaborator.doDispatch(PortletServletCollaborator.java:143)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:74)
    at com.ibm.ws.portletcontainer.rrd.RRDServerPortletServletCollaborator.doDispatch(RRDServerPortletServletCollaborator.java:60)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:74)
    at com.ibm.ws.portletcontainer.cache.CacheCollaborator.doDispatch(CacheCollaborator.java:74)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:74)
    at com.ibm.wps.pe.pc.waspc.core.impl.PortletServletCollaboratorImpl.doDispatch(PortletServletCollaboratorImpl.java:121)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:74)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServlet.dispatch(PortletServlet.java:208)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletServlet.service(PortletServlet.java:165)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1655)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1595)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:104)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:932)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:500)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:121)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.include(WebAppRequestDispatcher.java:673)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerImpl.invoke(PortletInvokerImpl.java:214)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerCollaboratorChainImpl.doCollaborator(PortletInvokerCollaboratorChainImpl.java:76)
    at com.ibm.ws.portletcontainer.cache.PortletInvokerCacheCollaborator.doAction(PortletInvokerCacheCollaborator.java:50)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerCollaboratorChainImpl.doCollaborator(PortletInvokerCollaboratorChainImpl.java:65)
    at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.invoke(PortletInvokerPerformanceCollaborator.java:313)
    at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.doInvoke(PortletInvokerPerformanceCollaborator.java:101)
    at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.invokePMI(PortletInvokerPerformanceCollaborator.java:163)
    at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.doInvoke(PortletInvokerPerformanceCollaborator.java:91)
    at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.doAction(PortletInvokerPerformanceCollaborator.java:62)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerCollaboratorChainImpl.doCollaborator(PortletInvokerCollaboratorChainImpl.java:65)
    at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerImpl.action(PortletInvokerImpl.java:77)
    at com.ibm.ws.portletcontainer.PortletContainerImpl.doAction(PortletContainerImpl.java:186)
    at com.ibm.ws.portletcontainer.PortletContainerInvokerCollaboratorChainImpl.doCollaborator(PortletContainerInvokerCollaboratorChainImpl.java:78)
    at com.ibm.ws.portletcontainer.ext.ExtCollaborator.doAction(ExtCollaborator.java:58)
    at com.ibm.ws.portletcontainer.PortletContainerInvokerCollaboratorChainImpl.doCollaborator(PortletContainerInvokerCollaboratorChainImpl.java:65)
    at com.ibm.ws.portletcontainer.cache.CacheInvokerCollaborator.doAction(CacheInvokerCollaborator.java:76)
    at com.ibm.ws.portletcontainer.PortletContainerInvokerCollaboratorChainImpl.doCollaborator(PortletContainerInvokerCollaboratorChainImpl.java:65)
    at com.ibm.ws.portletcontainer.PortletContainerImpl.processPortletAction(PortletContainerImpl.java:152)
    at com.ibm.ws.portletcontainer.pcinvoker.PortletInvokerImpl$1.run(PortletInvokerImpl.java:59)
    at java.security.AccessController.doPrivileged(AccessController.java:251)
    at com.ibm.ws.portletcontainer.pcinvoker.PortletInvokerImpl.invokeProcessAction(PortletInvokerImpl.java:55)
    at com.ibm.wps.pe.pc.waspc.core.impl.PortletInvokerImpl$3.invoke(PortletInvokerImpl.java:116)
    at com.ibm.wps.pe.pc.waspc.core.impl.PortletInvokerImpl.invoke(PortletInvokerImpl.java:176)
    at com.ibm.wps.pe.pc.waspc.core.impl.PortletInvokerImpl.invokeProcessAction(PortletInvokerImpl.java:114)
    at com.ibm.wps.pe.pc.waspc.event.ActionEvent.execute(ActionEvent.java:78)
    at com.ibm.wps.pe.pc.waspc.event.EventQueueManager.processEventLoop(EventQueueManager.java:112)
    at com.ibm.wps.pe.pc.waspc.PortletContainerImpl.performEvents(PortletContainerImpl.java:206)
    at com.ibm.wps.pe.pc.PortletContainerImpl.performEvents(PortletContainerImpl.java:298)
    at com.ibm.wps.engine.phases.WPActionPhase.processPortlets(WPActionPhase.java:2505)
    at com.ibm.wps.engine.phases.WPActionPhase.execute(WPActionPhase.java:694)
    at com.ibm.wps.state.phases.AbstractActionPhase.next(AbstractActionPhase.java:130)
    at com.ibm.wps.engine.Servlet.callPortal(Servlet.java:801)
    at com.ibm.wps.engine.Servlet.doGet(Servlet.java:608)
    at com.ibm.wps.engine.Servlet.doPost(Servlet.java:834)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
    at com.ibm.wps.engine.Servlet.doFilter(Servlet.java:1188)
    at com.ibm.wps.resolver.servlet.ContentHandlerCleanup.doFilter(ContentHandlerCleanup.java:648)
    at com.ibm.wps.resolver.servlet.AbstractFilter.doFilter(AbstractFilter.java:82)
    at com.ibm.wps.engine.Servlet.service(Servlet.java:1179)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1655)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1595)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
    at com.ibm.wps.engine.ExtendedLocaleFilter.doFilter(ExtendedLocaleFilter.java:113)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
    at com.ibm.wps.resolver.friendly.servlet.FriendlySelectionFilter.doFilter(FriendlySelectionFilter.java:191)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
    at com.ibm.wps.mappingurl.impl.URLAnalyzer.doFilter(URLAnalyzer.java:365)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
    at com.ibm.wps.engine.VirtualPortalFilter.doFilter(VirtualPortalFilter.java:88)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
    at com.ibm.wps.state.filter.StateCleanup.doFilter(StateCleanup.java:89)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:932)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:500)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3826)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
    Caused by: javax.faces.application.ViewExpiredException: viewId:/jsp/benefitplannavigator/benefitPlanCoverage.jsp – View /jsp/benefitplannavigator/benefitPlanCoverage.jsp could not be restored.
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:186)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:104)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at com.ibm.faces.portlet.FacesPortlet.processAction(FacesPortlet.java:193)
    … 119 more

  16. i posted my doubts above plz respond me as soon as possible.
    i have tried with :
    1)
    com.sun.faces.enableRestoreView11Compatibility
    true

    2)

    The location where state information is saved.
    Valid values are ‘server’ (typically saved in HttpSession) and ‘client’ (typically
    saved as a hidden field in the form.
    Default is server.
    javax.faces.STATE_SAVING_METHOD
    client

    added in web.xml still i am getting ViewExpiredException…

  17. Hi.

    I tried the example with but deploying the app does not work because of:

    Exception sending context initialized event to listener instance of class com.sun.faces
    .config.ConfigureListener
    Invalid content was found starting with element ‘view-handler’. On
    e of ‘ :faces-config-extension}’ is expected.

    This example only works on jsf 2.0?

    Thanks.

  18. Hi Greg,

    Thank you very much for the example.

    Whenever session expires i want to redirect to the SessionExpiry.xhtml. This is working fine for the facelets components(h:commandButton) but not with the richfaces component(a4j:commandButton).

    Could you plz help me in this regard.

    Thank in advance

  19. JSF Session Expires on Login Page (how can I prevent it?)

    Hi Greg,

    I dont want the session expire in Login Page , for Ex.. if user enters the credential and leave the page open forever and come back and giving login request it should navigate the Home page ,

    But they are still getting timed out and receiving ViewExpiredExceptions. Then its edirecting to the Error Page which i define in web.xml

    Is there a good way to make a page independent of the JSF session data? I want users to be able to leave the page open forever and come back and still have a working page.

    I don’t want the user to leave their browser on the login page, have the view expire while they are away, come back and type in their password just to be redirected to the login page and have to retype everything again. That just doesn’t make sense to me.

    Any help would be appreciated, thanks.

  20. Pingback: Javax.faces.facesexception Problem In Renderresponse | Real Estate

  21. Arindam Kotal

    Hi Greg,
    I am facing a complete different situation for the ViewState parameter.
    In Our application, If we trace the request in Fiddler after successful login to the application the first POST request contains a parameter javax.faces.viewState with some encrypted value. Now, in fiddler if I try to change the value of the ViewState parameter it is causing EOFException and printing a stack trace in the browser.

    How can I prevent to display the Exception in the browser and showing customized message to the user. In web.xml I have already done the below changes:

    java.lang.Exception
    /error.jsp

    But, it didn’t work. Can you please help me to get rid of the issue.

    1. Have you tried adding a generic 404/500 handler ?

       
      <error-page>
         <error-code>404</error-code>
         <location>/error-404.jsp</location>
      </error-page>
      <error-page>
         <error-code>500</error-code>
         <location>/error-500.jsp</location>
      </error-page>
  22. Pingback: Invalid Viewstate Error

Leave a Comment

Your email address will not be published. Required fields are marked *