{
return;
}
ExternalContext extContext = context.getExternalContext();
RenderResponse renderResponse = (RenderResponse) extContext.getResponse();
try
{
// set request attribute indicating we can deal with content
// that is supposed to be delayed until after JSF tree is ouput.
extContext.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 portlet
// Bridge has had to set this attribute so Faces RI will skip servlet dependent
// code when mapping from request paths to viewIds -- however we need to remove it
// as it screws up the dispatch
extContext.getRequestMap().remove("javax.servlet.include.servlet_path");
extContext.dispatch(viewToRender.getViewId());
/*
* if (executePageToBuildView(context, viewToRender)) { response.flushBuffer(); return; }
*/
}
catch (IOException e)
{
throw new FacesException(e);
}
// If a redirect occurred -- merely return
// check here to see if a redirect occurred -- if so rerun doFacesRequest
// for this new view
QueryString redirectParams = (QueryString) context.getExternalContext()
.getRequestMap().get(BridgeImpl.REDIRECT_VIEWPARAMS);
if ((redirectParams != null))
{
return;
}
// 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, 4096);
ResponseWriter newWriter;
if (null != oldWriter)
{
newWriter = oldWriter.cloneWithWriter(strWriter);
}
else
{
newWriter = renderKit.createResponseWriter(strWriter, null,
renderResponse.getCharacterEncoding());
}
context.setResponseWriter(newWriter);
newWriter.startDocument();
doRenderView(context, viewToRender);
newWriter.endDocument();
// replace markers in the body content and write it to response.
ResponseWriter responseWriter;
// Dispatch may have output to an OutputStream instead of a Writer
Writer renderResponseWriter = null;
try {
renderResponseWriter = renderResponse.getWriter();
}
catch (IllegalStateException ise) {
// got this exception because we've called getOutputStream() previously
renderResponseWriter = new BufferedWriter(
new OutputStreamWriter(
renderResponse.getPortletOutputStream(),
renderResponse.getCharacterEncoding()));
}
if (null != oldWriter)
{
responseWriter = oldWriter.cloneWithWriter(renderResponseWriter);
}
else
{
responseWriter = newWriter.cloneWithWriter(renderResponseWriter);
}
context.setResponseWriter(responseWriter);
strWriter.write(responseWriter);
renderResponseWriter.flush();
if (null != oldWriter)
{
context.setResponseWriter(oldWriter);
}
Object content = extContext.getRequestMap().get(Bridge.AFTER_VIEW_CONTENT);
if (content != null)
{
if (content instanceof char[])
{
renderResponse.getWriter().write(new String((char[]) content));
}
else if (content instanceof byte[])
{
renderResponse.getWriter().write(new String((byte[]) content));
}
else
{
throw new IOException("PortletViewHandlerImpl: invalid" + "AFTER_VIEW_CONTENT buffer type");
}
}
renderResponse.flushBuffer();
}