title: keep getting javax.faces.application.ViewExpiredException: viewId with jsf 2
body: <p>Whatever I do I get javax.faces.application.ViewExpiredException: viewId. I know how to handle the exception (redirect to the main page again if I get the error), the issue is that any action I call from a commandButton is not executed.</p>
  
  <p>Basically I have a simple view with a commandButton with an action.. I press it and I get the viewExpiredException or if I handle the error, I don't get the error messages but still my commandButton does not work.</p>
  
  <p>I tried adding this:</p>
  
  <pre><code> &lt;context-param&gt;
       &lt;param-name&gt;javax.faces.PARTIAL_STATE_SAVING&lt;/param-name&gt;
       &lt;param-value&gt;client&lt;/param-value&gt;
   &lt;/context-param&gt;
  </code></pre>
  
  <p>but it doesn't work. I don't know what is going on..</p>
  
  <p>This is my view:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      lang="es"&gt;
  &lt;div class="container"&gt;
      &lt;h:form id="principal"&gt;
          &lt;h1&gt;Sistema de carga de publicaciones&lt;/h1&gt;
  
          &lt;h:outputText value="Ingrese el año por el que desea buscar publicaciones" /&gt;
          &lt;h:inputText
              id="year"
              value="#{publicaciones.año}" /&gt;
  
          &lt;h:commandButton
              style="display:block"
              id="boton-codigo-facultad"
              value="Buscar"
              type="submit"&gt;
          &lt;/h:commandButton&gt;
  
          &lt;h:panelGroup id="output"&gt;
              &lt;h:outputText
                  style="display:block"
                  value="Total publicaciones en la DB:#{publicaciones.totalPublicacionesDB}" /&gt;
              &lt;h:outputText
                  style="display:block"
                  value="Publicaciones obtenidas desde el WS:" /&gt;
              &lt;h:outputText
                  style="display:block"
                  value="Publicaciones nuevas:" /&gt;
          &lt;/h:panelGroup&gt;
          &lt;h:commandButton
              style="display:block"
              id="insertar"
              value="Cargar publicacion"
              action="#{insert.insertPublicacionDB}"&gt;
          &lt;/h:commandButton&gt;
      &lt;/h:form&gt;
  &lt;/div&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>backing bean:</p>
  
  <pre><code>@ManagedBean(name="insert")
  @ViewScoped
  public class comparaDatosBean implements Serializable {
  
      private static final long serialVersionUID = 1L;
      Map&lt;String, Object&gt; parametros=new HashMap&lt;String, Object&gt;();
      Map&lt;String, Object&gt; params2=new HashMap&lt;String, Object&gt;();
  
      @PostConstruct
      public void init(){
          System.out.println("pase por aqui!!");
      }
  
      public void insertPublicacionDB() throws SQLException {
          ApplicationContext applicationContext = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
          ControllerPublicacion controlador= (ControllerPublicacion) applicationContext.getBean("controllerPublicaciones");
          parametros.put("ut","234567876545555");
          parametros.put("py", 2013);
  
          params2.put("ut", "234567876545555");
          params2.put("bp","asjñldfkjsñd");
          params2.put("la", "Español");
          params2.put("ti","Publicacion de prueba");
          params2.put("py",2013);
          params2.put("sn", "234wf");
          params2.put("di", "asdfsf");
          params2.put("j9", "");
          params2.put("dt", "");
          params2.put("ga", "");
          params2.put("dt", "");
          params2.put("so", "");
          params2.put("fx", "");
          params2.put("ep", "");
          params2.put("issue", "");
          params2.put("parte","");
          params2.put("vl", "");
          params2.put("rp", "");
          params2.put("vinculada", null);
          params2.put("ji", "");
          params2.put("pd","");
          params2.put("pg", "");
          params2.put("pa","");
          params2.put("ab","");
          params2.put("pi", "");
          params2.put("numero_articulo", null);
          params2.put("tipo_carga_revista",null);
          params2.put("id",null );
          params2.put("su", "");
          System.out.println(params2.get("la"));
          if(controlador.existeEnDB(parametros)&gt;0){
              System.out.println("La publicacion ya existe en la Base de Datos");
          } else {
              controlador.insertPublicacion(params2);
              System.out.println("la publicacion ha sido añadida");
          }
  
      }
  
      public Map&lt;String, Object&gt; getParametros() {
          return parametros;
      }
  
      public void setParametros(Map&lt;String, Object&gt; parametros) {
          this.parametros = parametros;
      }
  
      public Map&lt;String, Object&gt; getParams2() {
          return params2;
      }
  
      public void setParams2(Map&lt;String, Object&gt; params2) {
          this.params2 = params2;
      }
  
  }
  </code></pre>
  
  <p>Error message:</p>
  
  <pre><code>GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/test] threw exception [viewId:/main.jsf - No se pudo restablecer la vista /main.jsf.] with root cause
  javax.faces.application.ViewExpiredException: viewId:/main.jsf - No se pudo restablecer la vista /main.jsf.
      at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:212)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
      at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
      at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
      at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
      at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
      at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
      at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:619)
  </code></pre>
  
  <p>What I need is to know why this is happening, not how to handle the exception.. I can't call any action from a commandButton because nothing happens.</p>