I’m using JSF 2.0 and I want to flush the buffer early (between head and response) as it is one of the best practices to improve performance. In this article BalusC shows how to do in in a JSP page (<% response.getWriter().flush(); %>), but I’m using xhtml pages.
Does anyone know how to do it?
Thanks!
Damian
If you’re using
<h:head>in JSF2, then you can in theory do this by explicitly flushing the underlying servlet output stream in theencodeEnd()method of theRendererassociated with the component.There are basically two ways to implement a custom renderer. If you want to be implementation independent, then you have write the entire
Rendereryourself which is a piece of work (although for a simple HTML<head>element this is not that hard). You can also choose to be implementation specific so that you end up with a simpler customRendererimplementation. Assuming that you’re using Mojarra, then you just have to extend thecom.sun.faces.renderkit.html_basic.HeadRenderer.E.g.
which you then register as follows in
faces-config.xml:However, this approach has caveats. JSF does not have the opportunity anymore to create a session whenever necessary, or to handle any exception as error page whenever an exception is been thrown in midst of rendering the view. I would not recommend this approach for JSF.