Search in sources :

Example 1 with Lifecycle

use of javax.faces.lifecycle.Lifecycle in project deltaspike by apache.

the class JsfClientWindowAwareLifecycleWrapper method attachWindow.

@Override
public void attachWindow(FacesContext facesContext) {
    lazyInit();
    boolean delegateWindowHandling = ClientWindowConfig.ClientWindowRenderMode.DELEGATED.equals(clientWindowConfig.getClientWindowRenderMode(facesContext));
    if (delegateWindowHandling) {
        try {
            //the first wrapper is always DeltaSpikeLifecycleWrapper which can't extend from LifecycleWrapper
            Lifecycle externalWrapper = ((DeltaSpikeLifecycleWrapper) this.wrapped).getWrapped();
            delegateAttachWindow(facesContext, externalWrapper);
        } catch (Exception e) {
            try {
                attachWindowOnUnwrappedInstance(facesContext, this.wrapped);
            } catch (Exception e1) {
                throw ExceptionUtils.throwAsRuntimeException(e);
            }
        }
    } else {
        ClientWindow clientWindow = BeanProvider.getContextualReference(ClientWindow.class);
        //trigger init - might lead to a redirect -> response-complete
        String windowId = clientWindow.getWindowId(facesContext);
        if (!facesContext.getResponseComplete() && !"default".equals(windowId)) {
            facesContext.getExternalContext().setClientWindow(new ClientWindowAdapter(clientWindow));
        }
    }
}
Also used : ClientWindow(org.apache.deltaspike.jsf.spi.scope.window.ClientWindow) Lifecycle(javax.faces.lifecycle.Lifecycle) ClientWindowAdapter(org.apache.deltaspike.jsf.impl.scope.window.ClientWindowAdapter) FacesException(javax.faces.FacesException)

Example 2 with Lifecycle

use of javax.faces.lifecycle.Lifecycle in project acs-community-packaging by Alfresco.

the class FacesHelper method getFacesContextImpl.

/**
 * Return a valid FacesContext for the specific context, request and response.
 * The FacesContext can be constructor for Servlet and Portlet use.
 *
 * @param context       ServletContext or PortletContext
 * @param request       ServletRequest or PortletRequest
 * @param response      ServletReponse or PortletResponse
 *
 * @return FacesContext
 */
private static FacesContext getFacesContextImpl(Object request, Object response, Object context, String viewRoot) {
    FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    // Doesn't set this instance as the current instance of FacesContext.getCurrentInstance
    FacesContext facesContext = contextFactory.getFacesContext(context, request, response, lifecycle);
    // Set using our inner class
    InnerFacesContext.setFacesContextAsCurrent(facesContext);
    // set a new viewRoot, otherwise context.getViewRoot returns null
    if (viewRoot == null) {
        viewRoot = FacesHelper.BROWSE_VIEW_ID;
    }
    UIViewRoot view = facesContext.getApplication().getViewHandler().createView(facesContext, viewRoot);
    facesContext.setViewRoot(view);
    return facesContext;
}
Also used : FacesContext(javax.faces.context.FacesContext) FacesContextFactory(javax.faces.context.FacesContextFactory) LifecycleFactory(javax.faces.lifecycle.LifecycleFactory) Lifecycle(javax.faces.lifecycle.Lifecycle) UIViewRoot(javax.faces.component.UIViewRoot)

Example 3 with Lifecycle

use of javax.faces.lifecycle.Lifecycle in project ma-core-public by infiniteautomation.

the class FacesExtensionFilter method doFilter.

/* (non-Javadoc)
     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
     */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    // Either set a private member
    // servletContext = filterConfig.getServletContext();
    // in your filter init() method or set it here like this:
    // ServletContext servletContext =
    // ((HttpServletRequest) request).getSession().getServletContext();
    // Note that the above line would fail if you are using any other
    // protocol than http
    // Doesn't set this instance as the current instance of
    // FacesContext.getCurrentInstance
    FacesContext facesContext = contextFactory.getFacesContext(servletContext, request, response, lifecycle);
    // Set using our inner class
    InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);
    try {
        // call the filter chain
        chain.doFilter(request, response);
    } finally {
        // Clean up after ourselves as FacesContext is a ThreadLocal object
        try {
            facesContext.release();
        } catch (IllegalStateException ex) {
            // Perhaps the FacesContext has already been released?
            log.warn("Double release of faces context?", ex);
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) FacesContextFactory(javax.faces.context.FacesContextFactory) LifecycleFactory(javax.faces.lifecycle.LifecycleFactory) Lifecycle(javax.faces.lifecycle.Lifecycle)

Aggregations

Lifecycle (javax.faces.lifecycle.Lifecycle)3 FacesContext (javax.faces.context.FacesContext)2 FacesContextFactory (javax.faces.context.FacesContextFactory)2 LifecycleFactory (javax.faces.lifecycle.LifecycleFactory)2 FacesException (javax.faces.FacesException)1 UIViewRoot (javax.faces.component.UIViewRoot)1 ClientWindowAdapter (org.apache.deltaspike.jsf.impl.scope.window.ClientWindowAdapter)1 ClientWindow (org.apache.deltaspike.jsf.spi.scope.window.ClientWindow)1