public class ViewExpiredExceptionHandler extends ExceptionSuppressor
The ViewExpiredExceptionHandler
will suppress any ViewExpiredException
and refresh the current page
by redirecting to the current URL with query string. Additionally, it will set a flash attribute indicating that the
ViewExpiredException
was handled by this exception handler.
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.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 the FullAjaxExceptionHandler
from taking over the handling of the ViewExpiredException
.
<factory> <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory> <exception-handler-factory>org.omnifaces.exceptionhandler.ViewExpiredExceptionHandlerFactory</exception-handler-factory> </factory>
It'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
ViewExpiredException
which was handled by this exception handler, then you can use
wasViewExpired()
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 by Faces.redirect(String, Object...)
and derivates.
ViewExpiredExceptionHandlerFactory
Modifier and Type | Field and Description |
---|---|
static String |
FLASH_ATTRIBUTE_VIEW_EXPIRED
The flash attribute name of a boolean value indicating that the previous request threw a
ViewExpiredException which was handled by this exception handler. |
PARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
Constructor and Description |
---|
ViewExpiredExceptionHandler(ExceptionHandler wrapped)
Construct a new view expired exception handler around the given wrapped exception handler.
|
Modifier and Type | Method and Description |
---|---|
protected void |
handleSuppressedException(FacesContext context,
Throwable suppressedException)
Set the flash attribute "org.omnifaces.view_expired".
|
static boolean |
wasViewExpired()
Returns
true if the previous request threw a ViewExpiredException which was handled by this
exception handler. |
getExceptionTypesToSuppress, handle
getHandledExceptionQueuedEvent, getHandledExceptionQueuedEvents, getRootCause, getUnhandledExceptionQueuedEvents, getWrapped, isListenerForSource, processEvent
public static final String FLASH_ATTRIBUTE_VIEW_EXPIRED
ViewExpiredException
which was handled by this exception handler.public ViewExpiredExceptionHandler(ExceptionHandler wrapped)
wrapped
- The wrapped exception handler.protected void handleSuppressedException(FacesContext context, Throwable suppressedException)
handleSuppressedException
in class ExceptionSuppressor
context
- The involved faces context.suppressedException
- The suppressed exception.public static boolean wasViewExpired()
true
if the previous request threw a ViewExpiredException
which was handled by this
exception handler.true
if the previous request threw a ViewExpiredException
which was handled by this
exception handler.Copyright © 2012–2022 OmniFaces. All rights reserved.