docs: @Override
    public void renderView(FacesContext context, UIViewRoot view) throws IOException
    {
        //Try not to use native objects in this class.  Both MyFaces and the bridge
        //provide implementations of buildView but they do not override this class.
        checkNull(context, "context");
        checkNull(view, "view");
        
        // do not render the view if the rendered attribute for the view is false
        if (!view.isRendered())
        {
            if (log.isLoggable(Level.FINEST))
            {
                log.finest("View is not rendered");
            }
            return;
        }
        
        // Check if the current view has already been built via VDL.buildView()
        // and if not, build it from here. This is necessary because legacy ViewHandler
        // implementations return null on getViewDeclarationLanguage() and thus
        // VDL.buildView() is never called. Furthermore, before JSF 2.0 introduced 
        // the VDLs, the code that built the view was in ViewHandler.renderView().
        if (!isViewBuilt(context, view))
        {
            buildView(context, view);
        }
    
        ExternalContext externalContext = context.getExternalContext();
    
        String viewId = context.getViewRoot().getViewId();
    
        if (log.isLoggable(Level.FINEST))
        {
            log.finest("Rendering JSP view: " + viewId);
        }
    
    
        // handle character encoding as of section 2.5.2.2 of JSF 1.1
        if(null != externalContext.getSession(false))
        {
          externalContext.getSessionMap().put(ViewHandler.CHARACTER_ENCODING_KEY, 
                  externalContext.getResponseCharacterEncoding());
        }
    
        // render the view in this method (since JSF 1.2)
        RenderKitFactory renderFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
        RenderKit renderKit = renderFactory.getRenderKit(context, view.getRenderKitId());
    
        ResponseWriter responseWriter = context.getResponseWriter();
        if (responseWriter == null)
        {
            responseWriter = renderKit.createResponseWriter(externalContext.getResponseOutputWriter(), 
                    null, externalContext.getRequestCharacterEncoding());
            context.setResponseWriter(responseWriter);
        }
        
        // try to enable the ResponseSwitch again (disabled in buildView())
        Object response = context.getExternalContext().getResponse();
        ResponseSwitch responseSwitch = getResponseSwitch(response);
        if (responseSwitch != null)
        {
            responseSwitch.setEnabled(true);
        }
    
        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)
        {
            responseSwitch.setEnabled(false);
        }
    
        // 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()
                .get(AFTER_VIEW_TAG_CONTENT_PARAM);
        externalContext.getRequestMap().remove(AFTER_VIEW_TAG_CONTENT_PARAM);
        
        // afterViewTagResponse is null if the current request is a partial request
        if (afterViewTagResponse != null)
        {
            afterViewTagResponse.flushToWriter(externalContext.getResponseOutputWriter(), 
                    externalContext.getResponseCharacterEncoding());
        }
    
        //TODO sobryan: Is this right?
        context.getResponseWriter().flush();
    }