Recently I had a hard time to figure out some NPE with ViewScoped beans. In my case some actions on the bean were not fired, so subsequent actions ended in a NPE because required objects where not initialized. Problem was happening only in Firefox in case the user pressed F5 after doing some stuff on the page.
I suspected off cache handling. Adding a phase listener to add the no cache headers solved the problem. This is the code I'm using: (don't know why but adding the same headers on my main facelets template didn't worked) /** * Desativa cache de páginas xhtml * * http://turbomanage.wordpress.com/2006/08/08/disable-browser-caching-in-jsf/ * https://code.google.com/p/omnifaces/source/browse/src/org/omnifaces/filter/CacheControlFilter.java?name=1.7 * * @author fjaekel */ public class CacheControlPhaseListener implements PhaseListener { private static final long serialVersionUID = 1L; @Override public PhaseId getPhaseId() { //System.out.println("response " + Formatter.formatDateTimeWithSeconds(new Date())); return PhaseId.RENDER_RESPONSE; } @Override public void afterPhase(PhaseEvent event) { } @Override public void beforePhase(PhaseEvent event) { FacesContext facesContext = event.getFacesContext(); //HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest(); //System.out.println(request.getRequestURI()); HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); response.setHeader("Cache-Control", "no-cache,no-store,must-revalidate"); response.setDateHeader("Expires", 0); response.setHeader("Pragma", "no-cache"); // Backwards compatibility for HTTP 1.0. } } 2014-10-22 8:12 GMT-02:00 Donatas Čiukšys <donatas.ciuk...@mitsoft.lt>: > Dear MyFaces experts, > > > > I’m using TomEE 1.7.1 Plus, MyFaces 2.2.5, PrimeFaces 4.0.21, Omnifaces > 1.8.1, OCPSoft Rewrite 2.0.12. > > State saving: CLIENT; Session timeout: 60minutes; most pages are using > @ViewScoped beans (javax.faces.view.ViewScoped); Partial state saving is > not disabled; Encryption and compression are disabled. > > > > Production system is working in general (4 requests per second), no user > complaints, but in logs I find these two stack traces (shown at the bottom) > constantly (2-3 cases per day). I don’t think that there are any problem > with MyFaces, but I seek any advice how to collect forensic info on what > causes the stack traces below. The problems is that I cannot reproduce > those cases on my dev machine (I try short session timeout, invalidating > sessions, multiple tabs, …). > > > > Google says, that using state saving: CLIENT should prevent > ViewExpiredExceptions. I double-checked, that all my ViewScoped and > SessionScoped beans are Serializable, and use only Serializable classes. > Yet still I get ViewExpiredException - No saved view state could be found > for the view identifier. What could be the reasons? > > > > I’m already printing for each stack trace all the request info I can think > of (as you see in the bottom), where could I dig for additional forensic > info? Does MyFaces have any tracing facility? > > > > java.lang.NullPointerException: null > > at > org.apache.myfaces.application.StateManagerImpl.restoreView(StateManagerImpl.java:147) > ~[myfaces-impl-2.2.5.jar:2.2.5] > > at > org.apache.myfaces.shared.view.ViewDeclarationLanguageBase.restoreView(ViewDeclarationLanguageBase.java:104) > ~[myfaces-impl-2.2.5.jar:2.2.5] > > at > org.apache.myfaces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:336) > ~[myfaces-impl-2.2.5.jar:2.2.5] > > at > javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper..java:82) > ~[myfaces-api-2.2.5.jar:2.2.5] > > at > javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper..java:82) > ~[myfaces-api-2.2.5.jar:2.2.5] > > at > org.omnifaces.viewhandler.RestorableViewHandler.restoreView(RestorableViewHandler.java:66) > ~[omnifaces-1.8.1.jar:1.8.1-20140603] > > at > org.ocpsoft.rewrite.faces.RewriteViewHandler.restoreView(RewriteViewHandler.java:102) > ~[rewrite-integration-faces-2.0.12.Final.jar:2.0.12.Final] > > at > org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:168) > ~[myfaces-impl-2.2.5.jar:2.2.5] > > at > org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:196) > [myfaces-impl-2.2.5.jar:2.2.5] > > at > org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:143) > [myfaces-impl-2.2.5.jar:2.2.5] > > at > javax.faces.webapp.FacesServlet.service(FacesServlet.java:198) > [myfaces-api-2.2.5.jar:2.2.5] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) > [tomcat7-websocket.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205) > [rewrite-servlet-2.0.12.Final.jar:2.0.12.Final] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338) > [catalina.jar:7.0.55] > > at > org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler.handleResult(HttpRewriteResultHandler.java:41) > [rewrite-servlet-2.0.12.Final.jar:2.0.12.Final] > > at > org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:268) > [rewrite-servlet-2.0.12.Final.jar:2.0.12.Final] > > at > org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:188) > [rewrite-servlet-2.0.12.Final.jar:2.0.12.Final] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > lt.asseco.tar.setup.jsf.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:30) > [CharacterEncodingFilter.class:na] > > at > org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:77) > [omnifaces-1.8.1.jar:1.8.1-20140603] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve..java:220) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve..java:122) > [catalina.jar:7.0.55] > > at > org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) > [tomee-catalina-1.7.1.jar:1.7.1] > > at > org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) > [catalina.jar:7.0.55] > > at > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) > [catalina.jar:7.0.55] > > at > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) > [catalina.jar:7.0.55] > > at > org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:188) > [tomcat-coyote.jar:7.0.55] > > at > org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) > [tomcat-coyote.jar:7.0.55] > > at > org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2440) > [tomcat-coyote.jar:7.0.55] > > at > org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2429) > [tomcat-coyote.jar:7.0.55] > > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) > [na:1.7.0_67] > > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) > [na:1.7.0_67] > > at > org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread..java:61) > [tomcat-coyote.jar:7.0.55] > > at java.lang.Thread.run(Thread.java:745) > [na:1.7.0_67] > > > > ERROR 2014-10-07 11:05:54,879 ##### REQUEST ANALYSIS #####: host: > 85.206.12.185, method: POST, requestURL: > https://www.e-tar.lt/portal/legalAct.html?documentId=6c1b67f0e01411e388bee944977d73d2, > AJAX: false, sessionId: 06A20B649055AC25B4455630ABB84966.asHost2, > userAgent: Mozilla/5.0 (Windows NT 6.0; rv:32.0) Gecko/20100101 > Firefox/32.0, contentTypesFromAccept: > text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 > > javax.faces.application.ViewExpiredException: /portal/legalAct.html - No > saved view state could be found for the view identifier: > /portal/legalAct.html > > at > org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:181) > ~[myfaces-impl-2.2.5.jar:2.2.5] > > at > org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:196) > [myfaces-impl-2.2.5.jar:2.2.5] > > at > org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:143) > [myfaces-impl-2.2.5.jar:2.2.5] > > at > javax.faces.webapp.FacesServlet.service(FacesServlet.java:198) > [myfaces-api-2.2.5.jar:2.2.5] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) > [tomcat7-websocket.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205) > [rewrite-servlet-2.0.12.Final.jar:2.0.12.Final] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338) > [catalina.jar:7.0.55] > > at > org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler.handleResult(HttpRewriteResultHandler.java:41) > [rewrite-servlet-2.0.12.Final.jar:2.0.12.Final] > > at > org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:268) > [rewrite-servlet-2.0.12.Final.jar:2.0.12.Final] > > at > org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:188) > [rewrite-servlet-2.0.12.Final.jar:2.0.12.Final] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > lt.asseco.tar.setup.jsf.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:30) > [CharacterEncodingFilter.class:na] > > at > org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:77) > [omnifaces-1.8.1.jar:1.8.1-20140603] > > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve..java:220) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve..java:122) > [catalina.jar:7.0.55] > > at > org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) > [tomee-catalina-1.7.1.jar:1.7.1] > > at > org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) > [catalina.jar:7.0.55] > > at > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) > [catalina.jar:7.0.55] > > at > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) > [catalina.jar:7.0.55] > > at > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) > [catalina.jar:7.0.55] > > at > org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:188) > [tomcat-coyote.jar:7.0.55] > > at > org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) > [tomcat-coyote.jar:7.0.55] > > at > org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2440) > [tomcat-coyote.jar:7.0.55] > > at > org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2429) > [tomcat-coyote.jar:7.0.55] > > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) > [na:1.7.0_67] > > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) > [na:1.7.0_67] > > at > org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread..java:61) > [tomcat-coyote.jar:7.0.55] > > at java.lang.Thread.run(Thread.java:745) > [na:1.7.0_67] >