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

The following examples show how to use javax.faces.context.FacesContext#renderResponse() . 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
@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
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 4
@Override
public void navigateTo(Class<? extends ViewConfig> targetView)
{
    FacesContext facesContext = FacesContext.getCurrentInstance();
    facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, targetView.getName());
    facesContext.renderResponse();
}
 
Example 5
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
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 7
/**
 * {@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 8
Source Project: oxTrust   File: GlobalExceptionHandler.java    License: 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 9
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
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 11
/**
 * {@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 12
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
/**
 * {@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 14
/**
 * {@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 15
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
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 17
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 18
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 19
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
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();
}