• Settings
    • Locale
    • Change the locale of the datepicker, schedule and client side validation messages.

      Language
      English
      English
      English
      French
      German
      German
      German
      Italian
      Korean
      Spanish
      Catalan
      Dutch
      Portuguese
      Portuguese
      Arabic
      Arabic
      Bulgarian
      Bangla
      Bosnian
      Czech
      Greek
      Estonian
      Persian
      Finnish
      Danish
      Hindi
      Indonesian
      Icelandic
      Croatian
      Japanese
      Hungarian
      Hebrew
      Georgian
      Central Kurdish
      Khmer
      Kyrgyz
      Kazakh
      Lithuanian
      Latvian
      Malay
      Norwegian
      Polish
      Romanian
      Russian
      Slovak
      Slovenian
      Serbian
      Serbian
      Swedish
      Thai
      Turkish
      Ukrainian
      Uzbek
      Vietnamese
      Chinese
      Chinese
  • Resources

ExceptionHandler

PrimeFaces provides a powerful ExceptionHandler out of the box with following features:

  • featuring support for AJAX and non-AJAX requests
  • ability to use error-page configuration in web.xml
  • an EL extension called #{pfExceptionHandler} to provide information about the exception
  • p:ajaxExceptionHandler component to customize AJAX exception handling on the current view

AjaxExceptionHandler Tag Documentation

AjaxExceptionHandler is a utility component for the built-in ExceptionHandler.

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered boolean false true Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
widgetVar String false generated ('widget_' + componentClientId) Name of the client side widget.
onexception String false Client-side callback to execute when an exception occurs.
type String false Exception type to handle. If not specified, handles all exceptions.
update String false Component(s) to update after exception handling.
Loading...
Tag DocumentationNew DocumentationNew Documentation
AJAX
Non-AJAX

Usage


<div class="card">
    <h:form>
        <h5 class="mt-0">AJAX</h5>
        <p:commandButton action="#{exceptionHandlerView.throwViewExpiredException}"
                         ajax="true"
                         value="Throw ViewExpiredException!" styleClass="mr-2" />
        <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!" styleClass="mr-2"/>

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


        <p:ajaxExceptionHandler type="jakarta.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}' occurred!"
                  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 == 'jakarta.faces.application.ViewExpiredException'}"/>
        </p:dialog>
    </h:form>
</div>