https://java.net/jira/browse/JAVASERVERFACES-3171
Consider this Facelets page:
exceptionDuringRender.xhtml
<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">
<f:view contentType="text/html"/>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Exception During Render</title>
</h:head>
<h:body>
<p><span id="exceptionDuringRender"/> </p>
<script type="text/javascript">
var handleError = function handleError(data) {
var errorMessageString = "Error from " + data.source.id;
var span = document.getElementById("exceptionDuringRender");
span.innerHTML = errorMessageString;
}
jsf.ajax.addOnError(handleError);
</script>
<h:form prependId="false">
<h:outputText id="willThrowException" value="#{bean.throwExceptionOnAjax}" />
<h:commandButton id="submit" value="submit">
<f:ajax execute="@form" render=":willThrowException" />
</h:commandButton>
</h:form>
</h:body>
</html>
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">
<changes>
<update id="willThrowException">
<![CDATA[
<partial-response id="j_id1">
]]>
</update>
</changes>
<error>
<error-name>class java.lang.RuntimeException</error-name>
<error-message>
<![CDATA[
Intentionally throwing exception on ajax request
]]>
</error-message>
</error>
</partial-response>
Is this ok?
Ed
--
| edward.burns_at_oracle.com | office: +1 407 458 0017
| 12 Work Days Til DevNexus 2014
| 29 Work Days Til JavaLand 2014