Java Code Examples for javax.faces.context.FacesContext.getCurrentPhaseId()

The following are Jave code examples for showing how to use getCurrentPhaseId() of the javax.faces.context.FacesContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: admin-template   File: CustomExceptionHandler.java   View Source Code Vote up 5 votes
/**
 * @param context
 * @param e
 * @throws Throwable
 */
private void goToErrorPage(FacesContext context, Throwable e) {
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    request.setAttribute(ERROR_EXCEPTION + "_stacktrace", e);

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        throw new FacesException(e);
    }

    if (e instanceof FileNotFoundException) {
        logger.log(Level.WARNING,"File not found", e);
        throw new FacesException(e);
    }


    request.setAttribute(ERROR_EXCEPTION_TYPE, e.getClass().getName());
    request.setAttribute(ERROR_MESSAGE, e.getMessage());
    request.setAttribute(ERROR_REQUEST_URI, request.getHeader("Referer"));
    request.setAttribute(ERROR_STATUS_CODE, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    String errorPage = findErrorPage(e);
    if (!has(errorPage)) {
        String errorPageParam = context.getExternalContext().getInitParameter(Constants.InitialParams.ERROR_PAGE);
        if (!has(errorPageParam)) {
            errorPage = Constants.DEFAULT_ERROR_PAGE;
        }
    }
    context.getApplication().getNavigationHandler().handleNavigation(context, null, errorPage);
    context.renderResponse();
}
 
Example 2
Project: admin-template   File: CustomExceptionHandler.java   View Source Code Vote up 5 votes
/**
 * @param context
 * @param e       application business exception
 */
private void handleBusinessException(FacesContext context, BusinessException e) {
    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        throw new FacesException(e);
    }
    if (has(e.getExceptionList())) {
        for (BusinessException be : e.getExceptionList()) {
            addFacesMessage(be);
        }
    } else { //Single exception
        addFacesMessage(e);
    }
    validationFailed();
    context.renderResponse();
}