Skip to content

Instantly share code, notes, and snippets.

@novoj
Created August 28, 2013 12:13
Show Gist options
  • Save novoj/6365346 to your computer and use it in GitHub Desktop.
Save novoj/6365346 to your computer and use it in GitHub Desktop.
ServletFreemarkerRenderer_part
public void render(RequestContext context, WidgetDefinition widgetDefinition, TemplateReference templateReference, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws TemplateNotFoundException, TemplateProcessingException {
try {
//we have to set encoding before writer is fetche
try {
response.setCharacterEncoding(configuration.getDefaultEncoding());
} catch (NoSuchMethodError e) {
// servlet spec 2.3
response.setContentType("text/html; encoding=" + configuration.getDefaultEncoding());
}
PageDefinition pageDefinition = (PageDefinition) context.getRequestable();
response.setContentType(
pageDefinition.getContentType() + "; " + "charset=" + configuration.getDefaultEncoding()
);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "private");
//now render contents
render(context, widgetDefinition, templateReference, response.getWriter(),
new ServletFreemarkerRenderHandler(context)
);
}
catch (IOException e) {
String msg = "Cannot retrieve output stream: " + e.getLocalizedMessage();
log.error(msg);
throw new RuntimeException(msg, e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment