title: What is the canonical way to handle errors during Ajax-requests?
body: <p>For normal requests we can simple register an <code>&lt;error-page&gt;</code> in <code>web.xml</code>. However, this does not apply to Ajax-requests. By default errors during an Ajax-request will result in a little pop-window in the browser that shows the exception.</p>
  
  <p>The main example I am struggling with is handling a <code>ViewExpiredException</code> in a uniform way. For standard requests, I redirect to a page that explains that the user is not logged in and provides a link to the login-page. I would like to do the same for Ajax-requests. There seem to be several ways:</p>
  
  <ol>
  <li>I could write a javascript function that handles the error on the client-side and redirects to the error-page. I would then have to add this function <em>every <code>&lt;f:ajax&gt;</code>-tag on all pages</em> using the <code>onerror</code>-attribute. Is there a way to tell JSF that I want to have this javascript-function as the default error-handler for all <code>&lt;f:ajax&gt;</code>-tags?</li>
  <li>I could use a custom exception-handler, as described in <a href="http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2" rel="nofollow">this blog</a>. This seems to do what I want, but I wonder if it is overkill. Is there no simpler solution?</li>
  </ol>
  
  <p>So my question is, how is this supposed to be solved? Which of the approaches I listed should be used? Is there another approach that I do not know of?</p>