This is fairly long, but there are questions and possible pull requests inside.
I was following the spring MVC example in 1.6.1, and in the web.xml the spring configuration is an init-param to the DispatcherServlet. This works fine.
However, one of the "standard" ways of configuring spring in a webapp is to use a listener:
And this doesn't work. templateEngine in ScalateViewResolver is never initialised because setServletConfig() is never called (because there is no config for the DispatcherServlet). A solution is to use initServletContext(), which does get called:
public class MyResolver extends ScalateViewResolver {
protected void initServletContext(final ServletContext servletContext) {
super.initServletContext(servletContext);
super.setServletConfig(new ServletConfig() {
public String getServletName() { return "unknown"; }
public ServletContext getServletContext() { return servletContext; }
public Enumeration<String> getInitParameterNames() { return null; }
public String getInitParameter(String arg0) { return null; }
And this seems to work. So, question 1: does this seem a reasonable approach? What are the advantages / disadvantages of this?
I know that I can't specify parameters to ServletTemplateEngine such as boot.class, compiler.classpath.prefix, compiler.classpath.suffix, but I could always pass them in manually, use context parameters in that case.
Question 2: should I do a PR to add initServletContext into ServletViewResolver which does pretty much the same as the above. I could add context params for the boot.class etc is necessary. I'd need to avoid initialising twice of course.
Question 3: I spent a day or so trying to work this out. Do you want me to do a PR with a second example for spring mvc (in scala or java)?
Also, it took me a while to figure out how to set up the model so that I could pass attributes to and use in the template, which I think is important for people to know. So the PR would include this, and probably form submission as well. I'm using scaml.
Thanks.
Matthew Farwell.