Class FacesMessageExceptionHandler
- java.lang.Object
-
- jakarta.faces.context.ExceptionHandler
-
- jakarta.faces.context.ExceptionHandlerWrapper
-
- org.omnifaces.exceptionhandler.FacesMessageExceptionHandler
-
- All Implemented Interfaces:
FacesListener
,SystemEventListener
,FacesWrapper<ExceptionHandler>
,EventListener
public class FacesMessageExceptionHandler extends ExceptionHandlerWrapper
The
FacesMessageExceptionHandler
will add every exception as a global FATAL faces message.Installation
This handler must be registered by a factory as follows in
faces-config.xml
in order to get it to run:<factory> <exception-handler-factory>org.omnifaces.exceptionhandler.FacesMessageExceptionHandlerFactory</exception-handler-factory> </factory>
Note
It's your own responsibility to make sure that the faces messages are being shown. Make sure that there's a
<h:messages>
or any equivalent component (OmniFaces, PrimeFaces, etc) is present in the view and that it can handle global messages and that it's explicitly or automatically updated in case of ajax requests. Also make sure that you don't have bugs in rendering of your views. This exception handler is not capable of handling exceptions during render response. It will fail silently.Customizing
FacesMessageExceptionHandler
If more fine grained control of creating the FATAL faces message is desired, then the developer can opt to extend this
FacesMessageExceptionHandler
and override the following method:- Since:
- 1.8
- Author:
- Bauke Scholtz
- See Also:
FacesMessageExceptionHandlerFactory
-
-
Constructor Summary
Constructors Constructor Description FacesMessageExceptionHandler(ExceptionHandler wrapped)
Construct a new faces message exception handler around the given wrapped exception handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
createFatalMessage(Throwable exception)
Create fatal message based on given exception which will in turn be passed toFacesContext.addMessage(String, jakarta.faces.application.FacesMessage)
.void
handle()
Set every exception as a global FATAL faces message.-
Methods inherited from class jakarta.faces.context.ExceptionHandlerWrapper
getHandledExceptionQueuedEvent, getHandledExceptionQueuedEvents, getRootCause, getUnhandledExceptionQueuedEvents, getWrapped, isListenerForSource, processEvent
-
-
-
-
Constructor Detail
-
FacesMessageExceptionHandler
public FacesMessageExceptionHandler(ExceptionHandler wrapped)
Construct a new faces message exception handler around the given wrapped exception handler.- Parameters:
wrapped
- The wrapped exception handler.
-
-
Method Detail
-
handle
public void handle()
Set every exception as a global FATAL faces message.- Overrides:
handle
in classExceptionHandlerWrapper
-
createFatalMessage
protected String createFatalMessage(Throwable exception)
Create fatal message based on given exception which will in turn be passed toFacesContext.addMessage(String, jakarta.faces.application.FacesMessage)
. The default implementation returnsThrowable.toString()
.- Parameters:
exception
- The exception to create fatal message for.- Returns:
- The fatal message created based on the given exception.
-
-