title: FullAjaxExceptionHandler does not redirect to error page for Ajax request
body: <p>I know there has been numerous questions here on this question, but almost all of them suggest adding the following code because there is another layer "above" the FullAjaxExceptionHandler that is sending a plain redirect instead of doing an Ajax redirect (see <a href="https://stackoverflow.com/questions/17296420/fullajaxexceptionhandler-does-not-show-session-expired-error-page-on-ajax-button">this similar question</a>):</p>
  
  <pre><code>if ("partial/ajax".equals(request.getHeader("Faces-Request"))) {
  // JSF ajax request. Return special XML response which instructs JavaScript that it should in turn perform a redirect.
  response.setContentType("text/xml");
  response.getWriter()
      .append("&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;")
      .printf("&lt;partial-response&gt;&lt;redirect url=\"%s\"&gt;&lt;/redirect&gt;&lt;/partial-response&gt;", loginURL);
  } else {
      // Normal request. Perform redirect as usual.
      response.sendRedirect(loginURL);
  }
  </code></pre>
  
  <p>My question is that I'm simply configuring Omnifaces's FullAjaxExceptionHandler to do all the error handling, I do not have Spring Security or container managed security that is intercepting the request before FullAjaxExceptionHandler can do it's thing. I can breakpoint into FullAjaxExceptionHandler and see that when the following lines of code is executed, my error page is still not being redirected. </p>
  
  <pre><code>String viewId = Faces.normalizeViewId(errorPageLocation);
  ViewHandler viewHandler = context.getApplication().getViewHandler();
  UIViewRoot viewRoot = viewHandler.createView(context, viewId);
  context.setViewRoot(viewRoot);
  context.getPartialViewContext().setRenderAll(true);
          ...
      context.renderResponse();
  </code></pre>
  
  <p>Instead, the Ajax request where the exception originated has this in it's response body:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
      &lt;partial-response&gt;
          &lt;changes&gt;
              &lt;update id="javax.faces.ViewRoot"&gt;&lt;![CDATA[&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;... html of error page here ... &lt;/html&gt;]]&gt;&lt;/update&gt;
              &lt;update id="javax.faces.ViewState"&gt;&lt;![CDATA[-3527653129719750158:5595502883804776498]]&gt;&lt;/update&gt;
          &lt;/changes&gt;
      &lt;/partial-response&gt;
  </code></pre>
  
  <p>It looks like FullAjaxExceptionHandler isn't doing what it's supposed to do, or am I missing something?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Attaching browser JS output console screen cap.<img src="https://i.stack.imgur.com/LRbwH.png" alt="JS output console"></p>
  
  <p><strong>Problem Identified</strong></p>
  
  <p>Turns out that the HTML of my error page is malformed, it contains the following snippet, which results in the mismatched tag error in the browser:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  //&lt;![CDATA[
  scrollTo(0, 0);
  //]]&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>This seemed to have closed the CDATA tag prematurely. This HTML was a result of the <code>&lt;h:outputScript/&gt;</code> tag, which I removed since I don't really need it.</p>