public int doStartTag() throws JspException { if (log.isTraceEnabled()) log.trace("entering ViewTag.doStartTag"); FacesContext facesContext = FacesContext.getCurrentInstance(); Object response = facesContext.getExternalContext().getResponse(); if (response instanceof ViewResponseWrapper) { try { pageContext.getOut().flush(); ((ViewResponseWrapper) response).flushToWrappedResponse(); } catch (IOException e) { throw new JspException("Can't write content above <f:view> tag" + " " + e.getMessage()); } } int retVal = super.doStartTag(); Config.set(pageContext.getRequest(), Config.FMT_LOCALE, facesContext.getViewRoot().getLocale()); if (log.isTraceEnabled()) log.trace("leaving ViewTag.doStartTag"); return retVal; }
/**Build the view-tree before rendering. * This is done by dispatching to the underlying JSP-page, effectively processing it, creating * components out of any text in between JSF components (not rendering the text to the output of course, this * will happen later while rendering), attaching these components * to the component tree, and buffering any content after the view-root. * * @param response The current response - it will be replaced while the view-building happens (we want the text in the component tree, not on the actual servlet output stream) * @param externalContext The external context where the response will be replaced while building * @param viewId The view-id to dispatch to * @return true if successfull, false if an error occurred during rendering * @throws IOException */ private boolean buildView(ServletResponse response, ExternalContext externalContext, String viewId) throws IOException { ViewResponseWrapper wrappedResponse = new ViewResponseWrapper((HttpServletResponse) response); externalContext.setResponse(wrappedResponse); externalContext.dispatch(viewId); externalContext.setResponse(response); boolean errorResponse = wrappedResponse.getStatus() < 200 || wrappedResponse.getStatus() > 299; if (errorResponse) { wrappedResponse.flushToWrappedResponse(); return false; } // store the wrapped response in the request, so it is thread-safe externalContext.getRequestMap().put(AFTER_VIEW_TAG_CONTENT_PARAM, wrappedResponse); return true; }