- java.lang.Object
- 
- jakarta.faces.context.ExceptionHandler
- 
- jakarta.faces.context.ExceptionHandlerWrapper
- 
- org.omnifaces.exceptionhandler.ExceptionSuppressor
- 
- org.omnifaces.exceptionhandler.ViewExpiredExceptionHandler
 
 
 
 
- 
- All Implemented Interfaces:
- FacesListener,- SystemEventListener,- FacesWrapper<ExceptionHandler>,- EventListener
 
 public class ViewExpiredExceptionHandler extends ExceptionSuppressor The ViewExpiredExceptionHandlerwill suppress anyViewExpiredExceptionand refresh the current page by redirecting to the current URL with query string. Additionally, it will set a flash attribute indicating that theViewExpiredExceptionwas handled by this exception handler.InstallationThis handler must be registered by a factory as follows in faces-config.xmlin order to get it to run:<factory> <exception-handler-factory>org.omnifaces.exceptionhandler.ViewExpiredExceptionHandlerFactory</exception-handler-factory> </factory>In case there are multiple exception handlers, best is to register this handler as last one in the chain. For example, when combined with FullAjaxExceptionHandler, this ordering will prevent theFullAjaxExceptionHandlerfrom taking over the handling of theViewExpiredException.<factory> <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory> <exception-handler-factory>org.omnifaces.exceptionhandler.ViewExpiredExceptionHandlerFactory</exception-handler-factory> </factory>NoteIt's your own responsibility to make sure that the end user gets some form of feedback as to why exactly the page is refreshed and any submitted input values are lost. In order to check whether the previous request threw a ViewExpiredExceptionwhich was handled by this exception handler, then you can usewasViewExpired()in managed beans and#{flash['org.omnifaces.view_expired'] eq true}in EL.This approach will not work when the refresh in turn triggers yet another redirect elsewhere in the logic. In case you want to retain the condition for the next request, then you need to ensure that the involved logic explicitly triggers Flash.keep(String)in order to keep the flash attribute for the subsequent request. In the scope of OmniFaces, this is already taken care of byFaces.redirect(String, Object...)and derivates.- Since:
- 3.9
- Author:
- Lenny Primak
- See Also:
- ViewExpiredExceptionHandlerFactory
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringFLASH_ATTRIBUTE_VIEW_EXPIREDThe flash attribute name of a boolean value indicating that the previous request threw aViewExpiredExceptionwhich was handled by this exception handler.- 
Fields inherited from class org.omnifaces.exceptionhandler.ExceptionSuppressorPARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
 
- 
 - 
Constructor SummaryConstructors Constructor Description ViewExpiredExceptionHandler(ExceptionHandler wrapped)Construct a new view expired exception handler around the given wrapped exception handler.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidhandleSuppressedException(FacesContext context, Throwable suppressedException)Set the flash attribute "org.omnifaces.view_expired".static booleanwasViewExpired()Returnstrueif the previous request threw aViewExpiredExceptionwhich was handled by this exception handler.- 
Methods inherited from class org.omnifaces.exceptionhandler.ExceptionSuppressorgetExceptionTypesToSuppress, handle
 - 
Methods inherited from class jakarta.faces.context.ExceptionHandlerWrappergetHandledExceptionQueuedEvent, getHandledExceptionQueuedEvents, getRootCause, getUnhandledExceptionQueuedEvents, getWrapped, isListenerForSource, processEvent
 
- 
 
- 
- 
- 
Field Detail- 
FLASH_ATTRIBUTE_VIEW_EXPIREDpublic static final String FLASH_ATTRIBUTE_VIEW_EXPIRED The flash attribute name of a boolean value indicating that the previous request threw aViewExpiredExceptionwhich was handled by this exception handler.- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
ViewExpiredExceptionHandlerpublic ViewExpiredExceptionHandler(ExceptionHandler wrapped) Construct a new view expired exception handler around the given wrapped exception handler.- Parameters:
- wrapped- The wrapped exception handler.
 
 
- 
 - 
Method Detail- 
handleSuppressedExceptionprotected void handleSuppressedException(FacesContext context, Throwable suppressedException) Set the flash attribute "org.omnifaces.view_expired".- Overrides:
- handleSuppressedExceptionin class- ExceptionSuppressor
- Parameters:
- context- The involved faces context.
- suppressedException- The suppressed exception.
 
 - 
wasViewExpiredpublic static boolean wasViewExpired() Returnstrueif the previous request threw aViewExpiredExceptionwhich was handled by this exception handler.- Returns:
- trueif the previous request threw a- ViewExpiredExceptionwhich was handled by this exception handler.
 
 
- 
 
-