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

The following examples show how to use javax.faces.context.FacesContext#getCurrentPhaseId() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, Throwable exception) {

    final HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    request.setAttribute(ERROR_EXCEPTION + "_stacktrace", exception);

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

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

    final String errorPage = this.getErrorPage(exception);

    context.getApplication().getNavigationHandler().handleNavigation(context, null, errorPage);

    context.renderResponse();
}
 
Example 2
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, Throwable exception) {

    final HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    request.setAttribute(ERROR_EXCEPTION + "_stacktrace", exception);

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

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

    final String errorPage = this.getErrorPage(exception);

    context.getApplication().getNavigationHandler().handleNavigation(context, null, errorPage);

    context.renderResponse();
}
 
Example 3
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, Throwable exception) {

    final HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    request.setAttribute(ERROR_EXCEPTION + "_stacktrace", exception);

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

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

    final String errorPage = this.getErrorPage(exception);

    context.getApplication().getNavigationHandler().handleNavigation(context, null, errorPage);

    context.renderResponse();
}
 
Example 4
Source Project: deltaspike   File: JsfMessageResolver.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected List<String> getMessageSources(MessageContext messageContext)
{
    List<String> result = new ArrayList<String>(super.getMessageSources(messageContext) /*unmodifiable-list*/);

    FacesContext facesContext = FacesContext.getCurrentInstance();

    if (facesContext == null || facesContext.getCurrentPhaseId() == null)
    {
        return result;
    }

    String bundleName = facesContext.getApplication().getMessageBundle();

    if (bundleName != null)
    {
        result.add(bundleName);
    }
    result.add(FacesMessage.FACES_MESSAGES); //default messages from jsf

    return result;
}
 
Example 5
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, BusinessLogicException exception) {

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

    final String i18nMessage = MessageSource.get(exception.getMessage());

    FacesUtils.clearMessages(context);
    Messages.add(FacesMessage.SEVERITY_ERROR, null, i18nMessage, exception.getParameters());

    context.renderResponse();
}
 
Example 6
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, Throwable exception) {

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

    FacesUtils.clearMessages(context);
    Messages.add(FacesMessage.SEVERITY_ERROR, null, MessageSource.get("error.core.constraint-violation"));

    context.renderResponse();
    FacesUtils.temporizeHiding("messages");
}
 
Example 7
Source Project: admin-template   File: CustomExceptionHandler.java    License: MIT License 5 votes vote down vote up
/**
 * @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);
    context.renderResponse();
}
 
Example 8
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, BusinessLogicException exception) {

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

    final String i18nMessage = MessageSource.get(exception.getMessage());

    FacesUtils.clearMessages(context);
    Messages.add(FacesMessage.SEVERITY_ERROR, null, i18nMessage, exception.getParameters());

    context.renderResponse();
}
 
Example 9
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, Throwable exception) {

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

    FacesUtils.clearMessages(context);
    Messages.add(FacesMessage.SEVERITY_ERROR, null, MessageSource.get("error.core.constraint-violation"));

    context.renderResponse();
}
 
Example 10
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, BusinessLogicException exception) {

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

    final String i18nMessage = MessageSource.get(exception.getMessage());

    FacesUtils.clearMessages(context);
    Messages.add(FacesMessage.SEVERITY_ERROR, null, i18nMessage, exception.getParameters());

    context.renderResponse();
}
 
Example 11
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, Throwable exception) {

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

    FacesUtils.clearMessages(context);
    Messages.add(FacesMessage.SEVERITY_ERROR, null, MessageSource.get("error.core.constraint-violation"));

    context.renderResponse();
}
 
Example 12
@Override
public void processEvent(SystemEvent event) throws AbortProcessingException
{
    //handle exceptions which occur in a phase-listener (beforePhase) for PhaseId.RENDER_RESPONSE
    //needed because #handle gets called too late in this case
    if (event instanceof ExceptionQueuedEvent)
    {
        ExceptionQueuedEvent exceptionQueuedEvent = (ExceptionQueuedEvent)event;
        FacesContext facesContext = exceptionQueuedEvent.getContext().getContext();

        if (facesContext.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE &&
            exceptionQueuedEvent.getContext().inBeforePhase())
        {
            Throwable exception = getRootCause(exceptionQueuedEvent.getContext().getException());

            if (exception instanceof AccessDeniedException)
            {
                processAccessDeniedException(exception);
            }
            else
            {
                ExceptionToCatchEvent exceptionToCatchEvent = new ExceptionToCatchEvent(exception);
                exceptionToCatchEvent.setOptional(true);

                this.beanManager.fireEvent(exceptionToCatchEvent);

                if (exceptionToCatchEvent.isHandled())
                {
                    return;
                }
            }
        }
    }
    super.processEvent(event);
}
 
Example 13
@Override
public Locale getLocale()
{
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (facesContext != null && facesContext.getCurrentPhaseId() != null)
    {
        UIViewRoot viewRoot = facesContext.getViewRoot();
        Locale result = null;
        if (viewRoot != null)
        {
            // if a ViewRoot is present we return the Locale from there
            result = viewRoot.getLocale();
        }

        if (result != null)
        {
            Iterator<Locale> supportedLocale = facesContext.getApplication().getSupportedLocales();

            boolean supportedLocaleConfigured = false;
            while (supportedLocale.hasNext())
            {
                supportedLocaleConfigured = true;
                if (result.equals(supportedLocale.next()))
                {
                    return result;
                }
            }

            if (!supportedLocaleConfigured)
            {
                return result;
            }
        }

        result = facesContext.getApplication().getDefaultLocale();

        if (result != null)
        {
            return result;
        }
    }

    // return the default Locale, if no Locale was found
    return super.getLocale();
}