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

The following examples show how to use javax.faces.context.FacesContext#renderResponse() . 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 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 2
Source File: DoubleSubmitAwarePhaseListener.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPhase(PhaseEvent event)
{
    FacesContext facesContext = event.getFacesContext();

    //only check full POST requests
    if (facesContext.isPostback() && !facesContext.getPartialViewContext().isAjaxRequest())
    {
        String receivedPostRequestToken = facesContext.getExternalContext()
            .getRequestParameterMap().get(PostRequestTokenMarker.POST_REQUEST_TOKEN_KEY);

        if (receivedPostRequestToken == null)
        {
            receivedPostRequestToken = findPostRequestTokenWithPrefix(facesContext);
        }

        if (!this.postRequestTokenManager.isValidRequest(receivedPostRequestToken))
        {
            facesContext.renderResponse();
        }
    }
}
 
Example 3
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 4
Source File: DefaultExceptionHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleViewExpiredException(ViewExpiredException vee) {
    LOG.log(Level.INFO, " handling viewExpiredException...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = vee.getViewId();
    LOG.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.renderResponse();
}
 
Example 5
Source File: DefaultExceptionHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleNotFoundException(Exception e) {
    LOG.log(Level.INFO, "handling exception:...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = "/error.xhtml";
    LOG.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.getViewRoot().getViewMap(true).put("ex", e);
    context.renderResponse();
}
 
Example 6
Source File: DefaultExceptionHandler.java    From spring4-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleNotFoundException(Exception e) {
    log.debug("handling exception:...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = "/error.xhtml";
    log.debug("view id @" + viewId);
    NavigationHandler nav =
            context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.getViewRoot().getViewMap(true).put("ex", e);
    context.renderResponse();
}
 
Example 7
Source File: DefaultExceptionHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleNotFoundException(Exception e) {
    LOG.log(Level.INFO, "handling exception:...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = "/error.xhtml";
    LOG.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.getViewRoot().getViewMap(true).put("ex", e);
    context.renderResponse();
}
 
Example 8
Source File: DefaultExceptionHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleViewExpiredException(ViewExpiredException vee) {
    LOG.log(Level.INFO, " handling viewExpiredException...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = vee.getViewId();
    LOG.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.renderResponse();
}
 
Example 9
Source File: DefaultExceptionHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleNotFoundException(Exception e) {
    LOG.log(Level.INFO, "handling exception:...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = "/error.xhtml";
    LOG.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.getViewRoot().getViewMap(true).put("ex", e);
    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: DefaultExceptionHandler.java    From ee7-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleViewExpiredException(ViewExpiredException vee) {
    log.log(Level.INFO, " handling viewExpiredException...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = vee.getViewId();
    log.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.renderResponse();
}
 
Example 13
Source File: DefaultExceptionHandler.java    From spring4-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleViewExpiredException(ViewExpiredException vee) {
    log.debug(" handling viewExpiredException...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = vee.getViewId();
    log.debug("view id @" + viewId);
    NavigationHandler nav =
            context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.renderResponse();
}
 
Example 14
Source File: DefaultExceptionHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleViewExpiredException(ViewExpiredException vee) {
    LOG.log(Level.INFO, " handling viewExpiredException...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = vee.getViewId();
    LOG.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.renderResponse();
}
 
Example 15
Source File: DefaultExceptionHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleNotFoundException(Exception e) {
    LOG.log(Level.INFO, "handling exception:...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = "/error.xhtml";
    LOG.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.getViewRoot().getViewMap(true).put("ex", e);
    context.renderResponse();
}
 
Example 16
Source File: GlobalExceptionHandler.java    From oxTrust with MIT License 5 votes vote down vote up
public void handle() throws FacesException {
    final Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();

    while (i.hasNext()) {
        ExceptionQueuedEvent event = i.next();
        ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();

        Throwable t = context.getException();
        final FacesContext fc = FacesContext.getCurrentInstance();
        final ExternalContext externalContext = fc.getExternalContext();
        try {
if (isSecurityException(t)) {
	performRedirect(externalContext, "/login.htm");
} else if (isConversationException(t)) {
	log.trace(t.getMessage(), t);
	performRedirect(externalContext, "/conversation_error.htm");
} if (isViewExpiredException(t)) {
                storeRequestURI();
                performRedirect(externalContext, "/login.htm");
} else {
	log.trace(t.getMessage(), t);
	performRedirect(externalContext, "/error.htm");
}
            fc.renderResponse();
        } finally {
            i.remove();
        }
    }
    getWrapped().handle();
}
 
Example 17
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 18
Source File: DefaultExceptionHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
private void handleViewExpiredException(ViewExpiredException vee) {
    LOG.log(Level.INFO, " handling viewExpiredException...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = vee.getViewId();
    LOG.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.renderResponse();
}
 
Example 19
Source File: DefaultExceptionHandler.java    From javaee8-jsf-sample with GNU General Public License v3.0 5 votes vote down vote up
private void handleNotFoundException(Exception e) {
    LOG.log(Level.INFO, "handling exception:...");
    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = "/error.xhtml";
    LOG.log(Level.INFO, "view id @" + viewId);
    NavigationHandler nav
            = context.getApplication().getNavigationHandler();
    nav.handleNavigation(context, null, viewId);
    context.getViewRoot().getViewMap(true).put("ex", e);
    context.renderResponse();
}
 
Example 20
Source File: DefaultViewNavigationHandler.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Override
public void navigateTo(Class<? extends ViewConfig> targetView)
{
    FacesContext facesContext = FacesContext.getCurrentInstance();
    facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, targetView.getName());
    facesContext.renderResponse();
}