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

The following examples show how to use javax.faces.context.FacesContext#getCurrentPhaseId() . 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
Source File: UndefinedExceptionHandler.java    From library with Apache License 2.0 6 votes vote down vote up
/**
 * {@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
Source File: UndefinedExceptionHandler.java    From web-budget with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@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
Source File: UndefinedExceptionHandler.java    From web-budget with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@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 File: JsfMessageResolver.java    From deltaspike with 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
Source File: BusinessLogicExceptionHandler.java    From library with Apache License 2.0 5 votes vote down vote up
/**
 * {@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
Source File: ConstraintViolationExceptionHandler.java    From library with Apache License 2.0 5 votes vote down vote up
/**
 * {@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 File: CustomExceptionHandler.java    From admin-template with 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
Source File: BusinessLogicExceptionHandler.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@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
Source File: ConstraintViolationExceptionHandler.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@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
Source File: BusinessLogicExceptionHandler.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@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
Source File: ConstraintViolationExceptionHandler.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@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
Source File: BridgeExceptionHandlerWrapper.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@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
Source File: JsfAwareLocaleResolver.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@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();
}