I have a Spring MVC web application that uses freemarker as the template language. I am currently working on the changes to flush the html head section rather than buffering the whole html and flushing at the end. I tried setting the auto_flush freemarker setting to false and used freemarker's builtin <#flush> directive as below, but that doesn't seem to work.
common-header.ftl
<head>
.......
</head>
<#flush>
page.ftl
<#include "common-header.ftl" />
<body>
.......
</body>
I would appreciate your help with this. Also, per the API documentation, autoFlush() seems to only work for pages which aren't composed with #include statements and require multiple Template.process() methods. If that's correct, should i write a custom template processor to handle the head and body sections in my page ? Any pointers would be helpful.
Update:
Tried using FreeMarkerView.java as the view class as it uses the default writer (PrinterWriter) of HttpServletResponse to process the writer. This doesn't work either though PrinterWriter does support flush() and the <#flush> freemarker directive in my template doesn't seem to be invoking this.
Tried extending the FreeMarkerView class to wrap the PrinterWriter inside a BufferedWriter, and that doesn't work as well.
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="suffix"><value>.ftl</value></property>
<property name="contentType"><value>text/html; charset=utf-8</value></property>
<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
<property name="exposeSpringMacroHelpers"><value>true</value></property>
</bean>
I would appreciate any help with this.