#31 Extensibility of FreemarkerServlet

open
nobody
None
5
2005-12-06
2005-12-06
Mika Goeckel
No

I just ran into a problem in the combination of
FreeMarker, Sitemesh, Spring and a custom
TemplateLoader (in my case from DB via Hibernate/Spring).
The Problem is the init() method of FreemarkerServlet
in combination with the private configuration variable.

What I do is, I extend
com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet
which extends the FreemarkerServlet itself.
In my class I want to inject a Spring
org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
by overriding the createConfiguration() method of
FreemarkerServlet.

But the init() method of the FreeMarkerServlet messes
around with my configuration, mainly it tries to set a
templatePath (which I don't have, because I load from DB).
It is not an option to overwrite init(), because the
configuration variable is private and I have no way to
set it myself.

The solution is to refactor the FreemarkerServlet a
bit, move some parts out of init into protected methods
(to allow customization in subclasses) and to make some
of the variables protected instead of private.

Discussion

  • Mika Goeckel
    Mika Goeckel
    2005-12-06

    patch

     
    Attachments