/*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* <p>
* 1: https://wmarkito.wordpress.com/2012/04/05/adding-global-exception-handling-using-jsf-2-x-exceptionhandler/
* <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
*/
public class CustomExceptionHandler extends ExceptionHandlerWrapper {
@Override
public void handle () throws FacesException {
- final Iterator<ExceptionQueuedEvent> i = this.getUnhandledExceptionQueuedEvents().iterator();
+ final Iterator<ExceptionQueuedEvent> iterator = this.getUnhandledExceptionQueuedEvents().iterator();
- while (i.hasNext()) {
- ExceptionQueuedEvent event = i.next();
+ while (iterator.hasNext()) {
+ ExceptionQueuedEvent event = iterator.next();
ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
// get the exception from context
Throwable t = context.getException();
- final FacesContext fc = FacesContext.getCurrentInstance();
- final Map<String, Object> requestMap = fc.getExternalContext().getRequestMap();
- final NavigationHandler nav = fc.getApplication().getNavigationHandler();
+ final FacesContext facesContext = FacesContext.getCurrentInstance();
+ final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+ final NavigationHandler nav = facesContext.getApplication().getNavigationHandler();
//here you do what ever you want with exception
try {
//redirect error page
requestMap.put("exceptionMessage", t.getMessage()); //NOI18N
- nav.handleNavigation(fc, null, "/error"); //NOI18N
- fc.renderResponse();
+ nav.handleNavigation(facesContext, null, "exception"); //NOI18N
+ facesContext.renderResponse();
// remove the comment below if you want to report the error in a jsf error message
// @TODO: JsfUtil.addErrorMessage(t.getMessage());
} finally {
//remove it from queue
- i.remove();
+ iterator.remove();
}
}