Package javax.faces.lifecycle

Examples of javax.faces.lifecycle.Lifecycle


        }

        // Create a FacesContext for this request if necessary
        LifecycleFactory lf = (LifecycleFactory)
            FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
        Lifecycle lifecycle = // FIXME - alternative lifecycle ids
            lf.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
        boolean created = false;
        FacesContext context = FacesContext.getCurrentInstance();
        if (context == null) {
            if (log.isTraceEnabled()) {
                log.trace("  Creating new FacesContext for '" + uri + "'");
            }
            created = true;
            FacesContextFactory fcf = (FacesContextFactory)
                FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
            context = fcf.getFacesContext(servlet.getServletContext(),
                                          request, response, lifecycle);
        }

        // Create a new view root
        ViewHandler vh = context.getApplication().getViewHandler();
        if (log.isTraceEnabled()) {
            log.trace("  Creating new view for '" + uri + "'");
        }
        context.setViewRoot(vh.createView(context, uri));

        // Cause the view to be rendered
        if (log.isTraceEnabled()) {
            log.trace("  Rendering view for '" + uri + "'");
        }
        try {
            lifecycle.render(context);
        } finally {
            if (created) {
                if (log.isTraceEnabled()) {
                    log.trace("  Releasing context for '" + uri + "'");
                }
View Full Code Here


                (List<BeanEntry>)_externalContext.getApplicationMap().get(INJECTED_BEAN_STORAGE_KEY);

        //Lifecycle lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
        for (Iterator<String> it = lifecycleFactory.getLifecycleIds(); it.hasNext();)
        {
            Lifecycle lifecycle = lifecycleFactory.getLifecycle(it.next());
           
            // add phase listeners
            for (String listenerClassName : getDispenser().getLifecyclePhaseListeners())
            {
                try
                {
                    PhaseListener listener = (PhaseListener)
                            ClassUtils.newInstance(listenerClassName, PhaseListener.class);

                    Object creationMetaData = getInjectionProvider().inject(listener);

                    injectedBeanStorage.add(new BeanEntry(listener, creationMetaData));

                    getInjectionProvider().postConstruct(listener, creationMetaData);
                    lifecycle.addPhaseListener(listener);
                }
                catch (ClassCastException e)
                {
                    log.severe("Class " + listenerClassName + " does not implement PhaseListener");
                }
                catch (InjectionProviderException e)
                {
                    log.log(Level.SEVERE, "Error while injecting PhaseListener", e);
                }
            }

            // if ProjectStage is Development, install the DebugPhaseListener
            FacesContext facesContext = getFacesContext();
            if (facesContext.isProjectStage(ProjectStage.Development) &&
                    MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isDebugPhaseListenerEnabled())
            {
                lifecycle.addPhaseListener(new DebugPhaseListener());
            }
        }
    }
View Full Code Here

    @Override
    public Lifecycle getLifecycle(String id) throws FacesException
    {
        //synchronized (_lifecycles)
        //{
            Lifecycle lifecycle = _lifecycles.get(id);
            if (lifecycle == null)
            {
                throw new IllegalArgumentException("Unknown lifecycle '" + id + "'.");
            }
            return lifecycle;
View Full Code Here

                (List<BeanEntry>)_externalContext.getApplicationMap().get(INJECTED_BEAN_STORAGE_KEY);

        //Lifecycle lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
        for (Iterator<String> it = lifecycleFactory.getLifecycleIds(); it.hasNext();)
        {
            Lifecycle lifecycle = lifecycleFactory.getLifecycle(it.next());
           
            // add phase listeners
            for (String listenerClassName : getDispenser().getLifecyclePhaseListeners())
            {
                try
                {
                    PhaseListener listener = (PhaseListener)
                            ClassUtils.newInstance(listenerClassName, PhaseListener.class);

                    Object creationMetaData = getInjectionProvider().inject(listener);

                    injectedBeanStorage.add(new BeanEntry(listener, creationMetaData));

                    getInjectionProvider().postConstruct(listener, creationMetaData);
                    lifecycle.addPhaseListener(listener);
                }
                catch (ClassCastException e)
                {
                    log.severe("Class " + listenerClassName + " does not implement PhaseListener");
                }
                catch (InjectionProviderException e)
                {
                    log.log(Level.SEVERE, "Error while injecting PhaseListener", e);
                }
            }

            // if ProjectStage is Development, install the DebugPhaseListener
            FacesContext facesContext = getFacesContext();
            if (facesContext.isProjectStage(ProjectStage.Development) &&
                    MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isDebugPhaseListenerEnabled())
            {
                lifecycle.addPhaseListener(new DebugPhaseListener());
            }
        }
    }
View Full Code Here

    // the application has inserted itself in this process and sets up
    // needed request attributes.
    List<String> preExistingAttributes = getRequestAttributes(request);

    FacesContext context = null;
    Lifecycle lifecycle = null;
    String scopeId = null;
    try
    {
      // Get the FacesContext instance for this request
      lifecycle = getLifecycle();
      context = getFacesContext(request, response, lifecycle, null);
  
      // in case a prior scope was managed temporarily on the session -- remove it
      request.getPortletSession().removeAttribute(BRIDGE_PACKAGE_PREFIX + REQUEST_SCOPE_ID_RENDER_PARAM);
     
      // For actions we only execute the lifecycle phase

      lifecycle.addPhaseListener(this);
     
      lifecycle.execute(context);

      // If responseComplete don't save any state as we aren't falling through to render
      // Usual occurs because of a redirect
      if (!context.getResponseComplete())
      {
        // navigation didn't redirect
       
        // Finalize the action response -- key here is the reliance on
        // ExternalContext.encodeActionURL to migrate info encoded
        // in the actionURL constructed from the target of this
        // navigation
        // into the ActionResponse so it can be decoded in the
        // asscociated portlet render.

        finalizeActionResponse(context);
       
        // Process any Public Render parameter changes
        processOutgoingPublicRenderParameters(context, request, response);
       
       
        // Now check to see if we need to save the scope
        // We don't save scope if the finalizeActionResponse detected
        // a mode change
        Boolean noScope = (Boolean) request.getAttribute(PortletExternalContextImpl.NO_SCOPE);
        if (noScope == null || noScope.equals(Boolean.FALSE))
        {
       
          // Each action starts a new "action lifecycle"
          // The Bridge preserves request scoped data and if so configured
          // Action Parameters for the duration of an action lifecycle
          scopeId = initBridgeRequestScope(request, response);

          // Before preserving the request scope data in the bridge's
          // request scope,
          // put the Faces view into request scope. This is done because
          // JSF 1.2 manages the tree save state opaquely exclusively in
          // the render phase -- I.e. there is no JSF 1.2 way of having
          // the
          // bridge manually save and restore the view
          saveFacesView(context);

          // Spec requires we preserve the FACES_VIEW_STATE parameter
          // in addition the portlet may be configured to preserve the
          // rest of them.
          saveActionParams(context);

          // Because the portlet model doesn't execute its render phase
          // within the same request scope but Faces does (assumes this),
          // preserve the request scope data and the Faces view tree at
          // RequestScope.
          saveBridgeRequestScopeData(context, scopeId, preExistingAttributes);
        }

      }

    }
    catch (Exception e)
    {
      mPortletConfig.getPortletContext().log("Exception thrown in doFacesRequest:action", e);
      if (!(e instanceof BridgeException))
      {
        e =  new BridgeException(e);
      }
      throw (BridgeException) e;
    }
    finally
    {
      dumpScopeId(scopeId, "ACTION_PHASE");
     
      if (lifecycle != null)
      {
        lifecycle.removePhaseListener(this);
      }

      if (context != null)
      {
        // remove the redirect attr so its not carried over to the
View Full Code Here

   
    // Make sure that at a minimum the current render parameters are carried forward
    response.setRenderParameters(request.getParameterMap());

    FacesContext context = null;
    Lifecycle lifecycle = null;
    String scopeId = getRequestScopeId(request);
    if (scopeId != null)
    {
      // Its possible we didn't detect the mode change but its the wrong scope
      // as the scope is encoded with the mode -- confirm its right
      StringBuffer sb = new StringBuffer(10);
      String modeCheck = sb.append(":").append(request.getPortletMode().toString()).append(":").toString();
      if (scopeId.indexOf(modeCheck) < 0 )
      {
        // scope is for a different mode
        scopeId = null;
      }
    }
    boolean restoredScope = false;
   
    restoredScope = restoreBridgeRequestScopeData(request, scopeId);
   
    try
    {
      lifecycle = getLifecycle();
      // Get the FacesContext instance for this request
      context = getFacesContext(request, response, lifecycle, null);
     
      if (restoredScope)
      {
        // only restores if a render has never occurred in this scope
        // once a render occurs, the view is saved/restored via Faces
        restoreFacesView(context, scopeId);       
      }
  
      // in case a prior scope was managed temporarily on the session -- remove it
      // also ensure that the scopeId is now carried forward as a renderParameter
      request.getPortletSession().removeAttribute(BRIDGE_PACKAGE_PREFIX + REQUEST_SCOPE_ID_RENDER_PARAM);
      if (scopeId != null)
      {
        response.setRenderParameter(REQUEST_SCOPE_ID_RENDER_PARAM, scopeId);
      }
     
      // add self as PhaseListener to prevent action phase from executing (after restoreView)
      lifecycle.addPhaseListener(this);

      // For actions we only execute the lifecycle phase
      lifecycle.execute(context);
     
      // call the eventhandler to process
      EventNavigationResult result = mEventHandler.handleEvent(context, request.getEvent());
     
      // If redirected either during lifecycle or event handling merely return as new target is already encoded in response.
      if (context.getResponseComplete()) return;
     
      if (result != null)
      {
        context.getApplication().getNavigationHandler().handleNavigation(context, result.getFromAction(), result.getOutcome());
      }

      finalizeActionResponse(context);
       
      // Process any Public Render parameter changes
      processOutgoingPublicRenderParameters(context, request, response);
       
       
      // Now check to see if we need to save the scope
      // We don't save scope if the finalizeActionResponse detected
      // a mode change
      Boolean noScope = (Boolean) request.getAttribute(PortletExternalContextImpl.NO_SCOPE);
      if (noScope == null || noScope.equals(Boolean.FALSE))
      {
       
        // If event occurred before an action we don't have acope yet
        if (scopeId == null)
        {
          scopeId = initBridgeRequestScope(request, response);
         
          // TBD: Mojarra 1.2_05 or later sets responseComplete if the restore occurs in
          // a request that doesn't contain the isPostback marker (VIEW_STATE_PARAM).
          // If we have no scopeId it means we received an event before the portlet
          // was asked to render.  In these versions the following render call will
          // fail to render because there is no VIEW_STATE_PARAM.  Should we artifucally
          // set this here?
        }

        // Before preserving the request scope data in the bridge's
        // request scope,
        // put the Faces view into request scope. This is done because
        // JSF 1.2 manages the tree save state opaquely exclusively in
        // the render phase -- I.e. there is no JSF 1.2 way of having
        // the
        // bridge manually save and restore the view
        saveFacesView(context);

        // Because the portlet model doesn't execute its render phase
        // within the same request scope but Faces does (assumes this),
        // preserve the request scope data and the Faces view tree at
        // RequestScope.
        saveBridgeRequestScopeData(context, scopeId, preExistingAttributes);
      }

    }
    catch (Exception e)
    {
      mPortletConfig.getPortletContext().log("Exception thrown in doFacesRequest:event", e);
      if (!(e instanceof BridgeException))
      {
        e = new BridgeException(e);
      }
      throw (BridgeException) e;
    }
    finally
    {
      dumpScopeId(scopeId, "EVENT_PHASE");
      if (lifecycle != null)
      {
        lifecycle.removePhaseListener(this);
      }

      if (context != null)
      {
        // remove the redirect attr so its not carried over to the
View Full Code Here

    FacesContext context = null;
    try
    {
      // Get the FacesContext instance for this request
      Lifecycle lifecycle = getLifecycle();
      context = getFacesContext(request, response, lifecycle, redirectParams);
      ExternalContext extCtx = context.getExternalContext();

      // Use request from ExternalContext in case its been wrapped by an
      // extension
View Full Code Here

    FacesContext context = null;
    try
    {
      // Get the FacesContext instance for this request
      Lifecycle lifecycle = getLifecycle();
      context = getFacesContext(request, response, lifecycle, null);
      ExternalContext extCtx = context.getExternalContext();

      // Use request from ExternalContext in case its been wrapped by an
      // extension
View Full Code Here

    @Override
    public Lifecycle getLifecycle(String id) throws FacesException
    {
        //synchronized (_lifecycles)
        //{
            Lifecycle lifecycle = _lifecycles.get(id);
            if (lifecycle == null)
            {
                throw new IllegalArgumentException("Unknown lifecycle '" + id + "'.");
            }
            return lifecycle;
View Full Code Here

                = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
       
        //Lifecycle lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
        for (Iterator<String> it = lifecycleFactory.getLifecycleIds(); it.hasNext();)
        {
            Lifecycle lifecycle = lifecycleFactory.getLifecycle(it.next());
           
            // add phase listeners
            for (String listenerClassName : getDispenser().getLifecyclePhaseListeners())
            {
                try
                {
                    lifecycle.addPhaseListener((PhaseListener)
                            ClassUtils.newInstance(listenerClassName, PhaseListener.class));
                }
                catch (ClassCastException e)
                {
                    log.severe("Class " + listenerClassName + " does not implement PhaseListener");
                }
            }

            // if ProjectStage is Development, install the DebugPhaseListener
            FacesContext facesContext = FacesContext.getCurrentInstance();
            if (facesContext.isProjectStage(ProjectStage.Development) &&
                    MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isDebugPhaseListenerEnabled())
            {
                lifecycle.addPhaseListener(new DebugPhaseListener());
            }
        }
    }
View Full Code Here

TOP

Related Classes of javax.faces.lifecycle.Lifecycle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.