if (log.isLoggable(Level.FINEST))
log.finest("View is not rendered");
return;
}
ExternalContext externalContext = facesContext.getExternalContext();
String viewId = facesContext.getViewRoot().getViewId();
if (log.isLoggable(Level.FINEST))
log.finest("Rendering JSP view: " + viewId);
ServletResponse response = (ServletResponse) externalContext.getResponse();
ServletRequest request = (ServletRequest) externalContext.getRequest();
Locale locale = viewToRender.getLocale();
response.setLocale(locale);
Config.set(request, Config.FMT_LOCALE, facesContext.getViewRoot().getLocale());
if(!buildView(response, externalContext, viewId)) {
//building the view was unsuccessful - an exception occurred during rendering
//we need to jump out
return;
}
// handle character encoding as of section 2.5.2.2 of JSF 1.1
if (externalContext.getRequest() instanceof HttpServletRequest)
{
HttpServletRequest httpServletRequest = (HttpServletRequest) externalContext.getRequest();
HttpSession session = httpServletRequest.getSession(false);
if (session != null)
{
session.setAttribute(ViewHandler.CHARACTER_ENCODING_KEY, response.getCharacterEncoding());
}
}
// render the view in this method (since JSF 1.2)
RenderKitFactory renderFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
RenderKit renderKit = renderFactory.getRenderKit(facesContext, viewToRender.getRenderKitId());
ResponseWriter responseWriter = facesContext.getResponseWriter();
if (responseWriter == null)
{
responseWriter = renderKit.createResponseWriter(response.getWriter(), null,
((HttpServletRequest) externalContext.getRequest()).getCharacterEncoding());
facesContext.setResponseWriter(responseWriter);
}
ResponseWriter oldResponseWriter = responseWriter;
StateMarkerAwareWriter stateAwareWriter = null;
StateManager stateManager = facesContext.getApplication().getStateManager();
if (stateManager.isSavingStateInClient(facesContext))
{
stateAwareWriter = new StateMarkerAwareWriter();
// 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 = hookInStateAwareWriter(
oldResponseWriter, stateAwareWriter, renderKit, externalContext);
facesContext.setResponseWriter(responseWriter);
}
actuallyRenderView(facesContext, viewToRender);
facesContext.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(facesContext))
{
stateAwareWriter.flushToWriter(response.getWriter());
}
else
{
stateManager.saveView(facesContext);
}
// 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
ServletViewResponseWrapper afterViewTagResponse = (ServletViewResponseWrapper) externalContext.getRequestMap().get(
AFTER_VIEW_TAG_CONTENT_PARAM);
externalContext.getRequestMap().remove(AFTER_VIEW_TAG_CONTENT_PARAM);
if (afterViewTagResponse != null)
{
afterViewTagResponse.flushToWriter(response.getWriter(),
facesContext.getExternalContext().getResponseCharacterEncoding());