I found the solution. You need to sub-class the FreemarkerView to add the include behaviour:
public class CustomFreeMarkerView extends FreeMarkerView
{
private TaglibFactory taglibFactory;
private ServletContextHashModel servletContextHashModel;
@Override
protected void doRender( Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response )
throws Exception
{
// Expose model to JSP tags (as request attributes).
exposeModelAsRequestAttributes( model, request );
// Expose all standard FreeMarker hash models.
model.put( FreemarkerServlet.KEY_JSP_TAGLIBS, this.taglibFactory );
model.put( FreemarkerServlet.KEY_APPLICATION,
this.servletContextHashModel );
model.put( FreemarkerServlet.KEY_SESSION, buildSessionModel( request,
response ) );
model.put( FreemarkerServlet.KEY_REQUEST, new HttpRequestHashModel(
request, response, getObjectWrapper() ) );
model.put( FreemarkerServlet.KEY_REQUEST_PARAMETERS,
new HttpRequestParametersHashModel( request ) );
model.put( FreemarkerServlet.KEY_INCLUDE, new IncludePage( request,
response ) );
if ( logger.isDebugEnabled() )
{
logger.debug( "Rendering FreeMarker template [" + getUrl()
+ "] in FreeMarkerView '" + getBeanName() + "'" );
}
// Grab the locale-specific version of the template.
Locale locale = RequestContextUtils.getLocale( request );
processTemplate( getTemplate( locale ), new SimpleHash( model ), response );
}
private HttpSessionHashModel buildSessionModel( HttpServletRequest request,
HttpServletResponse response )
{
HttpSession session = request.getSession( false );
if ( session != null )
{
return new HttpSessionHashModel( session, getObjectWrapper() );
}
else
{
return new HttpSessionHashModel( null, request, response,
getObjectWrapper() );
}
}
}
The key line:
model.put( FreemarkerServlet.KEY_INCLUDE, new IncludePage( request,
response ) );
and then sub-class the view resolver to utilise the custom view:
public class CustomFreeMarkerViewResolver extends FreeMarkerViewResolver
{
public CustomFreeMarkerViewResolver()
{
setViewClass( requiredViewClass() );
}
/**
* Requires {@link FreeMarkerView}.
*/
@Override
protected Class requiredViewClass()
{
return CustomFreeMarkerView.class;
}
}