Package javax.faces.application

Examples of javax.faces.application.StateManager


                try
                {
                    context.setResponseWriter(writer);

                    // force creation of session if saving state there
                    StateManager stateMgr = context.getApplication().getStateManager();
                    if (!stateMgr.isSavingStateInClient(context))
                    {
                        extContext.getSession(true);
                    }
                   
                    // render the view to the response
                    writer.startDocument();

                    view.encodeAll(context);

                    writer.endDocument();

                    // finish writing
                    writer.close();

                    boolean writtenState = stateWriter.isStateWritten();
                    // flush to origWriter
                    if (writtenState)
                    {
                        // =-= markoc: STATE_KEY is in output ONLY if
                        // stateManager.isSavingStateInClient(context)is true - see
                        // org.apache.myfaces.application.ViewHandlerImpl.writeState(FacesContext)
                        // TODO this class and ViewHandlerImpl contain same constant <!--@@JSF_FORM_STATE_MARKER@@-->
                        Object stateObj = stateMgr.saveView(context);
                        String content = stateWriter.getAndResetBuffer();
                        int end = content.indexOf(STATE_KEY);
                        // See if we can find any trace of the saved state.
                        // If so, we need to perform token replacement
                        if (end >= 0)
                        {
                            // save state
                            String stateStr;
                            if (stateObj == null)
                            {
                                stateStr = null;
                            }
                            else
                            {
                                stateMgr.writeState(context, stateObj);
                                stateStr = stateWriter.getAndResetBuffer();
                            }

                            int start = 0;
View Full Code Here


            ResponseWriter writer = origWriter.cloneWithWriter(stateWriter);
            context.setResponseWriter(writer);

            // force creation of session if saving state there
            StateManager stateMgr = context.getApplication().getStateManager();
            if (!stateMgr.isSavingStateInClient(context))
            {
                extContext.getSession(true);
            }

            long time = System.currentTimeMillis();

            // render the view to the response
            writer.startDocument();
            viewToRender.encodeAll(context);
            writer.endDocument();

            // finish writing
            writer.close();

            boolean writtenState = stateWriter.isStateWritten();
            // flush to origWriter
            if (writtenState)
            {
                String content = stateWriter.getAndResetBuffer();
                int end = content.indexOf(STATE_KEY);
                // See if we can find any trace of the saved state.
                // If so, we need to perform token replacement
                if (end >= 0)
                {
                    // save state
                    Object stateObj = stateMgr.saveSerializedView(context);
                    String stateStr;
                    if (stateObj == null)
                    {
                        stateStr = null;
                    }
                    else
                    {
                        stateMgr.writeState(context, (StateManager.SerializedView) stateObj);
                        stateStr = stateWriter.getAndResetBuffer();
                    }

                    int start = 0;
View Full Code Here

      }
 
      ResponseWriter oldResponseWriter = responseWriter;
      StringWriter stateAwareWriter = null;
 
      StateManager stateManager = context.getApplication().getStateManager();
      if (stateManager.isSavingStateInClient(context))
      {
          stateAwareWriter = new StringWriter();
 
          // Create a new response-writer using as an underlying writer the stateAwareWriter
          // Effectively, all output will be buffered in the stateAwareWriter so that later
          // this writer can replace the state-markers with the actual state.
          responseWriter = oldResponseWriter.cloneWithWriter(stateAwareWriter);
          context.setResponseWriter(responseWriter);
      }
 
      actuallyRenderView(context, view);
     
      if(oldResponseWriter != null)
      {
          context.setResponseWriter(oldResponseWriter);   
      }
     
 
      // We're done with the document - now we can write all content
      // to the response, properly replacing the state-markers on the way out
      // by using the stateAwareWriter
      if (stateManager.isSavingStateInClient(context))
      {
          flushBufferToWriter(stateAwareWriter.getBuffer(), externalContext.getResponseOutputWriter());
      }
      else
      {
          stateManager.saveView(context);
      }
 
      // Final step - we output any content in the wrappedResponse response from above to the response,
      // removing the wrappedResponse response from the request, we don't need it anymore
      ViewResponseWrapper afterViewTagResponse = (ViewResponseWrapper) externalContext.getRequestMap()
View Full Code Here

  }
 
  protected void flushBufferToWriter(StringBuffer buff, Writer writer) throws IOException
  {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    StateManager stateManager = facesContext.getApplication().getStateManager();

    StringWriter stateWriter = new StringWriter();
    ResponseWriter realWriter = facesContext.getResponseWriter();
    facesContext.setResponseWriter(realWriter.cloneWithWriter(stateWriter));

    Object serializedView = stateManager.saveView(facesContext);

    stateManager.writeState(facesContext, serializedView);
    facesContext.setResponseWriter(realWriter);

    String state = stateWriter.getBuffer().toString();

    ExternalContext extContext = facesContext.getExternalContext();
View Full Code Here

     */
    public void encodeAjax(FacesContext context, UIComponent component) throws IOException
    {
        encodeInnerHtml(context, component);
         if (context.getApplication().getStateManager().isSavingStateInClient(context)){
            StateManager stateManager = context.getApplication().getStateManager();
            StateManager.SerializedView serializedView = stateManager.saveSerializedView(context);
            Object compStates =  serializedView.getState();

            StringBuffer buf = new StringBuffer();

            buf.append("jsf_state=");
View Full Code Here

            addChildParametersToHref(component, hrefBuf,
                                     false, //not the first url parameter
                                     writer.getCharacterEncoding());
        }

        StateManager stateManager = facesContext.getApplication().getStateManager();
        if (stateManager.isSavingStateInClient(facesContext))
        {
            hrefBuf.append("&");
            hrefBuf.append(URL_STATE_MARKER);
        }
        String href = facesContext.getExternalContext().encodeActionURL(hrefBuf.toString());
View Full Code Here

        // in theory the state should be a black box, but the RI makes assumptions
        // that the state is an array of length 2
        if (stateArray.length == 2)
        {
          StateManager stateManager =
            context.getApplication().getStateManager();
          view =
              stateManager.new SerializedView(stateArray[0], stateArray[1]);
        }
        else
View Full Code Here

      throws IOException {
    StringWriter jsfState = new StringWriter();
    ResponseWriter stateWriter = renderKit.createResponseWriter(jsfState, null, null);
    facesContext.setResponseWriter(stateWriter);

    StateManager stateManager = facesContext.getApplication().getStateManager();
    StateManager.SerializedView serializedView
        = stateManager.saveSerializedView(facesContext);
    stateManager.writeState(facesContext, serializedView);
    return jsfState.toString();
  }
View Full Code Here

      }
 
      ResponseWriter oldResponseWriter = responseWriter;
      StringWriter stateAwareWriter = null;
     
      StateManager stateManager = context.getApplication().getStateManager();
      boolean viewStateAlreadyEncoded = isViewStateAlreadyEncoded(context);
     
      if (!viewStateAlreadyEncoded)
      {
        // we will need to parse the reponse and replace the view_state token with the actual state
        stateAwareWriter = new StringWriter();
 
        // Create a new response-writer using as an underlying writer the stateAwareWriter
        // Effectively, all output will be buffered in the stateAwareWriter so that later
        // this writer can replace the state-markers with the actual state.
        responseWriter = oldResponseWriter.cloneWithWriter(stateAwareWriter);
        context.setResponseWriter(responseWriter);
      }
 
      try
      {
        if (!actuallyRenderView(context, view))
        {
          return;
        }
      }
      finally
      {
        if(oldResponseWriter != null)
        {
            context.setResponseWriter(oldResponseWriter);   
        }
      }
 
      if (!viewStateAlreadyEncoded)
      {
        // parse the response and replace the token wit the state
        flushBufferToWriter(stateAwareWriter.getBuffer(), externalContext.getResponseOutputWriter());
      }
      else
      {
        stateManager.saveView(context);
      }
     
      // now disable the ResponseSwitch again
      if (responseSwitch != null)
      {
View Full Code Here

  protected boolean isViewStateAlreadyEncoded(FacesContext context)
  {
    if (MyfacesConfig.getCurrentInstance(context.getExternalContext()).isMyfacesImplAvailable())
    {
      // In MyFaces the viewState key is already encoded is server side state saving is being used
      StateManager stateManager = context.getApplication().getStateManager();
      return !context.getApplication().getStateManager().isSavingStateInClient(context);
    }
    else
    {
      return false;
View Full Code Here

TOP

Related Classes of javax.faces.application.StateManager

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.