ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
Throwable t = context.getException();
final FacesContext fc = FacesContext.getCurrentInstance();
final NavigationHandler nav = fc.getApplication().getNavigationHandler();
try {
// change exception for different jpa provider as this is what
// hibernate throws in case of optimistic lock failure.
if (unwindException(t) instanceof StaleObjectStateException) {
FacesUtils.error("error.optimisticLocking");
nav.handleNavigation(fc, null, null);
fc.renderResponse();
} else if (t instanceof ViewExpiredException) {
FacesUtils.error("error.sessionExpired");
nav.handleNavigation(fc, null, "/login.xhtml");
fc.renderResponse();
}
} finally {