// Set the new ResponseWriter into the FacesContext, saving the old one aside.
ResponseWriter responseWriter = facesContext.getResponseWriter();
//Now we actually render the document
// Call startDocument() on the ResponseWriter.
responseWriter.startDocument();
// Call encodeAll() on the UIViewRoot
viewToRender.encodeAll(facesContext);
// Call endDocument() on the ResponseWriter