title: Handle ViewExireException/ajax and display a Primefaces dialog
body: <p>I don't redirect or forward my user to another page. So when the my <code>SessionExpiredExceptionHandler</code> (extends <code>ExceptionHandlerWrapper</code>) handles the ViewExireException. I want the user to stay on the same page and display a PrimeFaces Dialog. For notifying that the session has expired and that the user needs to login again (dialog based). I am use Servlet 3.1 functions to login/logout user and <code>Basic/file</code> for auth-method to map the users to different system roles. </p>
  
  <p>What is happening now is that the View/page get refreshed after 2 min, but the session doesn't get invalidated. That only happens the second time when the page refreshes, after 4 min.</p>
  
  <pre><code>    &lt;session-config&gt;
          &lt;session-timeout&gt;2&lt;/session-timeout&gt;
      &lt;/session-config&gt;
  </code></pre>
  
  <p><strong>Edit:</strong>
  Which is refreshed by the meta tag:</p>
  
  <pre><code>&lt;meta http-equiv="refresh" content="#{session.maxInactiveInterval}" /&gt;
  </code></pre>
  
  <p>How can I make <code>SessionExpiredExceptionHandler</code>invalidate the session object (Servlet logout) when the Exceptions occur the first time, and how can I invoke a JavaScript (expireDlg.show()) on the client to display a PrimeFaces dialog ?</p>
  
  <p>I have looked at some other threads but not found a viable solution.
  <a href="https://stackoverflow.com/questions/11203195/session-timeout-and-viewexpiredexception-handling-on-jsf-primefaces-ajax-request">Session time-out</a></p>
  
  <p>SessionExpiredExceptionHandler</p>
  
  <pre><code>    @Override
      public void handle() throws FacesException {
      for (Iterator&lt;ExceptionQueuedEvent&gt; i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
          ExceptionQueuedEvent event = i.next();
          ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
          Throwable t = context.getException();
          if (t instanceof ViewExpiredException) {
          ViewExpiredException vee = (ViewExpiredException) t;
          FacesContext fc = FacesContext.getCurrentInstance();
          Map&lt;String, Object&gt; requestMap = fc.getExternalContext().getRequestMap();
          NavigationHandler nav = fc.getApplication().getNavigationHandler();                
  
          try {
              requestMap.put("currentViewId", vee.getViewId());
  
              nav.handleNavigation(fc, null, "Home");
              fc.renderResponse();
  
          } finally {
              i.remove();
          }                                
          }
      }
      // At this point, the queue will not contain any ViewExpiredEvents.
      // Therefore, let the parent handle them.
      getWrapped().handle();
      }
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;exception-type&gt;javax.faces.application.ViewExpiredException&lt;/exception-type&gt;
      &lt;location&gt;/home.xhtml&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>