From b8b2fc094d0313626224371dcbdf18784d56d51f Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 1 Sep 2014 12:12:10 +0200 Subject: [PATCH] Umstellung auf Thymeleaf: Zwischenschritt - Fehler in Thymeleaf umschifft --- pom.xml | 5 ++ .../branding/web/ForceIncludeFilter.java | 55 +++++++++++++++++++ src/main/resources/spring/tiles.xml | 1 + src/main/webapp/WEB-INF/views/tiles.jsp | 5 ++ src/main/webapp/WEB-INF/web.xml | 14 +++++ .../webapp/thymeleaf/templates/layout.html | 2 + 6 files changed, 82 insertions(+) create mode 100644 src/main/java/de/juplo/branding/web/ForceIncludeFilter.java create mode 100644 src/main/webapp/WEB-INF/views/tiles.jsp diff --git a/pom.xml b/pom.xml index cf5f6688..256cbbc3 100644 --- a/pom.xml +++ b/pom.xml @@ -126,6 +126,11 @@ runtime + + org.apache.tiles + tiles-servlet + ${tiles.version} + diff --git a/src/main/java/de/juplo/branding/web/ForceIncludeFilter.java b/src/main/java/de/juplo/branding/web/ForceIncludeFilter.java new file mode 100644 index 00000000..953e8b23 --- /dev/null +++ b/src/main/java/de/juplo/branding/web/ForceIncludeFilter.java @@ -0,0 +1,55 @@ +package de.juplo.branding.web; + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.tiles.servlet.context.ServletUtil; + + + +/** + * Fixes a logic-bug in the colaboration of Thymeleaf and Tiles. + * + * Tiles 2.2.x tries to use RequestDispatcher.forward() whenever possible, but + * this breaks Thymeleaf, because the original response is marked as committed, + * when forwarding. Hence, Thymeleaf cannot render its result in the response + * and an empty page is returned. + * + * @author kai + */ +public class ForceIncludeFilter implements Filter +{ + + @Override + public void init(FilterConfig filterConfig) throws ServletException + { + } + + @Override + public void doFilter( + ServletRequest request, + ServletResponse response, + FilterChain chain + ) + throws + IOException, + ServletException + { + if ((response instanceof HttpServletResponse)) + ServletUtil.setForceInclude((HttpServletRequest)request, true); + + chain.doFilter(request, response); + } + + @Override + public void destroy() + { + } + +} diff --git a/src/main/resources/spring/tiles.xml b/src/main/resources/spring/tiles.xml index d9dd9a66..8439ff05 100644 --- a/src/main/resources/spring/tiles.xml +++ b/src/main/resources/spring/tiles.xml @@ -11,6 +11,7 @@ + + characterEncodingFilter org.springframework.web.filter.CharacterEncodingFilter @@ -40,6 +41,19 @@ + + + + forceIncludeFilter + de.juplo.branding.web.ForceIncludeFilter + + + + forceIncludeFilter + *.html + + + diff --git a/src/main/webapp/thymeleaf/templates/layout.html b/src/main/webapp/thymeleaf/templates/layout.html index f019b462..7d02e2b4 100644 --- a/src/main/webapp/thymeleaf/templates/layout.html +++ b/src/main/webapp/thymeleaf/templates/layout.html @@ -27,6 +27,8 @@

+ +
TILES
FOOTER
-- 2.20.1