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.

Documentation

AJAX

Non-AJAX

Exception '' occured!
Message:
StackTrace:
<h:form>
    <h3 style="margin-top:0">AJAX</h3>
    <p:commandButton action="#{exceptionHandlerView.throwViewExpiredException}"
                     ajax="true"
                     value="Throw ViewExpiredException!" />
    <p:commandButton action="#{exceptionHandlerView.throwNullPointerException}"
                     ajax="true"
                     value="Throw NullPointerException!" />
    <!-- IllegalStateException is not handled using ajaxExceptionHandlers below, so the error page is shown-->
    <p:commandButton action="#{exceptionHandlerView.throwWrappedIllegalStateException}"
                     ajax="true"
                     value="Throw IllegalStateException!" />

    <h3>Non-AJAX</h3>
    <p:commandButton action="#{exceptionHandlerView.throwViewExpiredException}"
                     ajax="false"
                     value="Throw ViewExpiredException!" />
    <!-- NullPointerException has no specific error-page defined in web.xml compared to ViewExpiredException -->
    <!-- https://github.com/primefaces/showcase-facelift/blob/master/src/main/webapp/WEB-INF/web.xml -->
    <p:commandButton action="#{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>

FREE THEMES

Built-in component themes created by the PrimeFaces Theme Designer.

nova-light Nova-Light
nova-dark Nova-Dark
nova-colored Nova-Colored
luna-blue Luna-Blue
luna-amber Luna-Amber
luna-green Luna-Green
luna-pink Luna-Pink
omega Omega

PREMIUM TEMPLATES

Create awesome applications in no time using the premium templates and impress your users.