Java Code Examples for javax.faces.context.Flash

The following examples show how to use javax.faces.context.Flash. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: joinfaces   Source File: JsfBeansAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean("flash")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS)
@ConditionalOnMissingBean
public Flash flash() {
	return FacesContext.getCurrentInstance().getExternalContext().getFlash();
}
 
Example 2
@Override
public void handle() throws FacesException
{
    lazyInit();
    Iterator<ExceptionQueuedEvent> exceptionQueuedEventIterator = getUnhandledExceptionQueuedEvents().iterator();

    while (exceptionQueuedEventIterator.hasNext())
    {
        ExceptionQueuedEventContext exceptionQueuedEventContext =
                (ExceptionQueuedEventContext) exceptionQueuedEventIterator.next().getSource();

        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
        Throwable throwable = exceptionQueuedEventContext.getException();

        String viewId = null;

        if (!isExceptionToHandle(throwable))
        {
            continue;
        }

        FacesContext facesContext = exceptionQueuedEventContext.getContext();
        Flash flash = facesContext.getExternalContext().getFlash();

        if (throwable instanceof ViewExpiredException)
        {
            viewId = ((ViewExpiredException) throwable).getViewId();
        }
        else if (throwable instanceof ContextNotActiveException)
        {
            //the error page uses a cdi scope which isn't active as well
            //(it's recorded below - see flash.put(throwable.getClass().getName(), throwable);)
            if (flash.containsKey(ContextNotActiveException.class.getName()))
            {
                //TODO show it in case of project-stage development
                break;
            }

            if (facesContext.getViewRoot() != null)
            {
                viewId = facesContext.getViewRoot().getViewId();
            }
            else
            {
                viewId = BeanProvider.getContextualReference(ViewConfigResolver.class)
                        //has to return a value otherwise this handler wouldn't be active
                        .getDefaultErrorViewConfigDescriptor().getViewId();
            }
        }

        if (viewId != null)
        {
            UIViewRoot uiViewRoot = facesContext.getApplication().getViewHandler().createView(facesContext, viewId);

            if (uiViewRoot == null)
            {
                continue;
            }

            if (facesContext.isProjectStage(javax.faces.application.ProjectStage.Development) ||
                    ProjectStageProducer.getInstance().getProjectStage() == ProjectStage.Development ||
                    ProjectStageProducer.getInstance().getProjectStage() instanceof TestStage)
            {
                throwable.printStackTrace();
            }

            facesContext.setViewRoot(uiViewRoot);
            exceptionQueuedEventIterator.remove();

            //record the current exception -> to check it at the next call or to use it on the error-page
            flash.put(throwable.getClass().getName(), throwable);
            flash.keep(throwable.getClass().getName());

            this.viewNavigationHandler.navigateTo(DefaultErrorView.class);

            break;
        }
    }

    this.wrapped.handle();
}