tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JMill <apprentice...@googlemail.com>
Subject Unable to find “Spring.ftl” file when using Freemarker and Tiles 3
Date Tue, 23 Dec 2014 22:09:37 GMT
Using Tiles 3 in combination with Freemarker within Spring MVC. According
to this unanswered post
<https://mail-archives.apache.org/mod_mbox/tiles-users/201307.mbox/%3CCAB2eobUxvHYmQGz-WgzZ4Cqxav1p-5z_GPWAUMCw1WWs3JyT1g@mail.gmail.com%3E>
the
cause of the following exception is due to the fact that
"exposeSpringMacroHelpers" property has not been set to true. Can I get
some feedback on if this is the case along with any possible solutions that
maybe available?

Extended TileView Class (see below) to enable "exposeSpringMacroHelpers"
but still get the following error, this leads me think it maybe something
else.

Exception

...Caused by: javax.servlet.ServletException: Error executing
FreeMarker template
  at freemarker.ext.servlet.FreemarkerServlet.process(FreemarkerServlet.java:463)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.ext.servlet.FreemarkerServlet.doGet(FreemarkerServlet.java:391)
~[freemarker-2.3.20.jar:2.3.20]
  at org.apache.tiles.request.freemarker.render.FreemarkerRenderer.render(FreemarkerRenderer.java:73)
~[tiles-request-freemarker-1.0.6.jar:1.0.6]
  ... 83 common frames omittedCaused by:
freemarker.core._MiscTemplateException: Error reading imported
template spring.ftl

The failing instruction:==> #import "/spring.ftl" as spring  [in
template "WEB-INF/layouts/default.ftl" at line 2, column 1]
  at freemarker.core.LibraryLoad.accept(LibraryLoad.java:118)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.core.Environment.visit(Environment.java:265)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.core.MixedContent.accept(MixedContent.java:93)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.core.Environment.visit(Environment.java:265)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.core.Environment.process(Environment.java:243)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.template.Template.process(Template.java:277)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.ext.servlet.FreemarkerServlet.process(FreemarkerServlet.java:452)
~[freemarker-2.3.20.jar:2.3.20]
  ... 85 common frames omittedCaused by:
java.io.FileNotFoundException: Template "spring.ftl" not found.
  at freemarker.template.Configuration.getTemplate(Configuration.java:742)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.core.Environment.getTemplateForInclusion(Environment.java:1694)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.core.Environment.getTemplateForImporting(Environment.java:1748)
~[freemarker-2.3.20.jar:2.3.20]
  at freemarker.core.LibraryLoad.accept(LibraryLoad.java:111)
~[freemarker-2.3.20.jar:2.3.20]
  ... 91 common frames omitted

Config Class

@Beanpublic UrlBasedViewResolver tilesViewResolver(){
    UrlBasedViewResolver urlBasedViewResolver = new UrlBasedViewResolver();
    urlBasedViewResolver.setViewClass(FreemarkerTilesView.class);
    return urlBasedViewResolver;}
@Beanpublic TilesConfigurer tilesConfigurer(){
    TilesConfigurer tilesConfigurer = new TilesConfigurer();
    tilesConfigurer.setCompleteAutoload(true);
    return tilesConfigurer;}

FreemarkerTilesView (extends TilesView)

public class FreemarkerTilesView extends TilesView {
    public static final String SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE =
            "springMacroRequestContext";

    private boolean exposeSpringMacroHelpers = true;

    public void setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers) {
        this.exposeSpringMacroHelpers = exposeSpringMacroHelpers;
    }


    public boolean getExposeSpringMacroHelpers() {
        return exposeSpringMacroHelpers;
    }

    @Override
    protected void renderMergedOutputModel(
            Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) throws Exception {

        if (this.exposeSpringMacroHelpers) {
            if (model.containsKey(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE)) {
                throw new ServletException(
                        "Cannot expose bind macro helper '" +
SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE +
                                "' because of an existing model object
of the same name");
            }
            model.put(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE,
                    new RequestContext(request, response,
getServletContext(), model));
        }

        super.renderMergedOutputModel(model, request, response);
    }}

Template (default.ftl)

<html lang="en">
<#import "/spring.ftl" as spring />
...</html>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message