What to do when an exception is thrown during ajax rendering?

From: Edward Burns <>
Date: Thu, 6 Feb 2014 13:14:01 -0800

Consider this Facelets page:


<html xmlns=""
<f:view contentType="text/html"/>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
    <title>Exception During Render</title>

    <p><span id="exceptionDuringRender"/>&nbsp;</p>

    <script type="text/javascript">

    var handleError = function handleError(data) {
        var errorMessageString = "Error from " +;
        var span = document.getElementById("exceptionDuringRender");
        span.innerHTML = errorMessageString;


    <h:form prependId="false">
        <h:outputText id="willThrowException" value="#{bean.throwExceptionOnAjax}" />
        <h:commandButton id="submit" value="submit">
            <f:ajax execute="@form" render=":willThrowException" />


If #{bean.throwExceptionOnAjax} throws an exception? What should happen
to the handleError()? It should get invoked, right?

Well, it doesn't. Instead, we get an exception about nested CDATA.

That's the first problem.

Once we fix the nested CDATA problem, we now see that the error handler
is not invoked because the status is not set to 500.

Here are my questions to the community.

Should an exception occurring during render cause an HTTP 500 error to
be set as the status of the Ajax response?

Should we allow the ajax error handler to take effect when the rendering
contains broken CDATA rendered response text?

I have a patch that makes it so both of things are true.

Here is the partial Ajax response with the proposed fix in place:

<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1">
    <update id="willThrowException">
                <partial-response id="j_id1">
  <error-name>class java.lang.RuntimeException</error-name>
              Intentionally throwing exception on ajax request

Is this ok?


| | office: +1 407 458 0017
| 12 Work Days Til DevNexus 2014
| 29 Work Days Til JavaLand 2014