ExceptionHandler PrimeFaces provides a powerful ExceptionHandler out of the box featuring support for ajax and non-ajax requests, ability to use error-page configuration in web.xml, an EL extension called to provide information about the exception and the p:ajaxExceptionHandler component to handle ajax exceptions at the same page.

AJAX

Non-AJAX

Exception '' occured!
Message:
StackTrace:
<h:form>
    <h3 style="margin-top:0">AJAX</h3>
    <p:commandButton actionListener="#{exceptionHandlerView.throwViewExpiredException}"
                     ajax="true"
                     value="Throw ViewExpiredException!" />
    <p:commandButton actionListener="#{exceptionHandlerView.throwNullPointerException}"
                     ajax="true"
                     value="Throw NullPointerException!" />
    <p:commandButton actionListener="#{exceptionHandlerView.throwWrappedIllegalStateException}"
                     ajax="true"
                     value="Throw IllegalStateException!" />

    <h3>Non-AJAX</h3>
    <p:commandButton actionListener="#{exceptionHandlerView.throwViewExpiredException}"
                     ajax="false"
                     value="Throw ViewExpiredException!" />
    <p:commandButton actionListener="#{exceptionHandlerView.throwNullPointerException}"
                     ajax="false"
                     value="Throw NullPointerException!" />


    <p:ajaxExceptionHandler type="javax.faces.application.ViewExpiredException"
                            update="exceptionDialog"
                            onexception="PF('exceptionDialog').show();" />

    <p:ajaxExceptionHandler type="java.lang.NullPointerException"
                            update="exceptionDialog"
                            onexception="PF('exceptionDialog').show();" />

    <p:dialog id="exceptionDialog" header="Exception '#{pfExceptionHandler.type}' occured!" widgetVar="exceptionDialog"
              height="500px">
        Message: #{pfExceptionHandler.message} <br/>
        StackTrace: <h:outputText value="#{pfExceptionHandler.formattedStackTrace}" escape="false" /> <br />

        <p:button onclick="document.location.href = document.location.href;"
                  value="Reload!"
                  rendered="#{pfExceptionHandler.type == 'javax.faces.application.ViewExpiredException'}" />
    </p:dialog>
</h:form>
                
PrimeTek, Copyright © 2015
All rights reserved.
Running PrimeFaces-6.0.16 on Mojarra-2.2.8.