}
private void doRenderView(FacesContext context, UIViewRoot viewToRender) throws IOException {
ExternalContext externalContext = context.getExternalContext();
MimeResponse renderResponse = (MimeResponse) externalContext
.getResponse();
try {
// set request attribute indicating we can deal with content
// that is supposed to be delayed until after JSF tree is ouput.
externalContext.getRequestMap().put(Bridge.RENDER_CONTENT_AFTER_VIEW,
Boolean.TRUE);
// TODO JSF 1.2 - executePageToBuildView() creates
// ViewHandlerResponseWrapper
// to handle error page and text that exists after the <f:view> tag
// among other things which have lots of servlet dependencies -
// we're skipping this for now for portletbridge
// extContext.dispatch(viewToRender.getViewId());
if (executePageToBuildView(context, viewToRender)) {
renderResponse.flushBuffer();
return;
}
} catch (IOException e) {
throw new FacesException(e);
}
// set up the ResponseWriter
RenderKitFactory renderFactory = (RenderKitFactory) FactoryFinder
.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
RenderKit renderKit = renderFactory.getRenderKit(context, viewToRender
.getRenderKitId());
ResponseWriter oldWriter = context.getResponseWriter();
StringBuilderWriter strWriter = new StringBuilderWriter(context,
renderResponse.getWriter(), 4096);
try {
ResponseWriter newWriter;
if (null != oldWriter) {
newWriter = oldWriter.cloneWithWriter(strWriter);
} else {
newWriter = renderKit.createResponseWriter(strWriter, null,
renderResponse.getCharacterEncoding());
}
context.setResponseWriter(newWriter);
newWriter.startDocument();
viewToRender.encodeAll(context);
newWriter.endDocument();
// replace markers in the body content and write it to response.
strWriter.flushToWriter();
} finally {
strWriter.release();
}
if (null != oldWriter) {
context.setResponseWriter(oldWriter);
}
renderResponse.flushBuffer();
}