Im currently trying out the ajax feature, and im curious about how can i display the error messages occured when i do the ajax stuff ? For example, i have a primefaces button :
<p:commandButton value="Refresh" update="debugPanel messages"
action="#{checkbocLabBean.submit}"/>
When testing that button, nothing seems to happen, until i check the server logs, there's an exception. It turns out that i have a typo. Should be #{checkboxLabBean.submit}.
The only thing i can think of right now is to have disable the ajax, adding ajax="false" in my case, and the error will show up.
Is there any other ways to show errors right into the browser in development phase when using ajax requests ?
Ajax requests happens asynchronously. They do by default not affect the entire document. Exceptions thrown during PrimeFaces' ajax requests are delegated to <p:ajaxStatus>
. You can do your thing in <facet name="error">
.
<p:ajaxStatus>
<f:facet name="start">Loading...</f:facet>
<f:facet name="success"><h:outputText value="" /></f:facet>
<f:facet name="error">An error has occurred!</f:facet>
</p:ajaxStatus>
If you rather want to replace the current document with the error page -which is a very reasonable choice- then it's good to know that PrimeFaces uses jQuery under the covers and that you can configure jQuery as follows to do so:
<script>
jQuery.ajaxSetup({
error: handleXhrError
});
function handleXhrError(xhr) {
document.open();
document.write(xhr.responseText);
document.close();
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With