Tiles 2 integration module - TemplateInputException

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Tiles 2 integration module - TemplateInputException

Eric Francis
I am trying to integrate jsp and thymeleaf pages into a tiles definition.

I am getting this error:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/WEB-INF/jsp/layout/layout.jsp", template might not exist or might not be accessible by any of the configured Template Resolvers
      at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:247)
      at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1192)
      at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1148)
      at org.thymeleaf.extras.tiles2.renderer.ThymeleafAttributeRenderer.write(ThymeleafAttributeRenderer.java:149)
      at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
      at org.thymeleaf.extras.tiles2.renderer.MetadataCleaningAttributeRendererWrapper.render(MetadataCleaningAttributeRendererWrapper.java:111)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)


Per the error, I believe I am having having an issue resolving layout.jsp.

This is my Tiles definition:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
        <definition name="baseLayout" template="/WEB-INF/jsp/layout/layout.jsp"
                templateType="jsp">
                <put-attribute name="header" value="/WEB-INF/jsp/layout/header.jsp"
                        type="jsp" />
                <put-attribute name="navigation" value="/WEB-INF/jsp/layout/navigation.jsp"
                        type="jsp" />
                <put-attribute name="body" value="" />
                <put-attribute name="footer" value="/WEB-INF/jsp/layout/footer.jsp"
                        type="jsp" />
        </definition>

        <definition name="welcome" extends="baseLayout">
                <put-attribute name="body" value="/WEB-INF/thymeleaf/welcome.html" />
        </definition>
</tiles-definitions>

As you can see, I am trying to use jsp attributes as well as thymeleaf attributes.

Any ideas on how to troubleshoot this error?
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Tiles 2 integration module - TemplateInputException

Eric Francis
Ok, I solved this.

I was confused by the templateResolver and the viewResolver.

I had:

@Bean
        public ServletContextTemplateResolver templateResolver() {
                ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
                templateResolver.setPrefix("/WEB-INF/thymeleaf/layout/");
                templateResolver.setSuffix(".html");
                templateResolver.setTemplateMode("HTML5");
                return templateResolver;
        }

And:

<definition name="baseLayout" template="/WEB-INF/thymeleaf/layout/layout.html" >
                <put-attribute name="body" value="" />
        </definition>

So spring was actually looking for a file named "/WEB-INF/thymeleaf/layout/layout.html" in the folder /WEB-INF/thymeleaf/layout/layout.html

I changed my definition to:

<definition name="baseLayout" template="layout" >
                <put-attribute name="body" value="" />
        </definition>

And now Spring is able to resolve the template location correctly.