Unable to redirect to error page in JSF using ExceptionHandlerWrapper

时间:2018-12-03 12:59:18

标签: jsf jsf-2 jsf-2.2

Below is the code snippet where the page is redirecting to error page when we have FaceletException, Run-time and User defined Exceptions but it is not redirecting when we have ComponentNotFoundException

public void handle() throws FacesException {

  final Iterator<ExceptionQueuedEvent> queue = getUnhandledExceptionQueuedEvents().iterator();

  while (queue.hasNext()) {

    ExceptionQueuedEvent item = queue.next();
    try {
      ExceptionQueuedEventContext exceptionQueuedEventContext = (ExceptionQueuedEventContext) item.getSource();

      Throwable exception = exceptionQueuedEventContext.getException();

      String uuid = UUID.randomUUID().toString();
      final FacesContext fc = FacesContext.getCurrentInstance();
      final Map<String, Object> requestMap = fc.getExternalContext().getRequestMap();
      final ConfigurableNavigationHandler nav = (ConfigurableNavigationHandler) fc.getApplication().getNavigationHandler();

      requestMap.put("exceptionMessage", exception.getMessage());
      requestMap.put("stackTrace", getStactTrace(exception));
      requestMap.put("UUID", uuid);

      if (isAjaxRequest(fc.getExternalContext().getRequestHeaderMap())) {

        nav.performNavigation("error.xhtml?faces-redirect=true");
      } else {
        LOG.info("IN NON Ajax Request Redirect");
        nav.handleNavigation(fc, null, "error.xhtml?faces-redirect=true");
      }
    } finally {
      // remove it from queue
      queue.remove();
    }
  }
  getWrapped().handle();
}

0 个答案:

没有答案