From 56c1247bbbdbb20025f035b322b1e853e3e3e013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ferna=CC=81ndez?= Date: Tue, 16 Oct 2018 01:40:01 +0200 Subject: [PATCH] Add new config keys for Thymeleaf 3.0.10 features This commit adds the following configuration properties: * `spring.thymeleaf.render-hidden-markers-before-checkboxes` * `spring.thymeleaf.servlet.produce-partial-output-while-processing` --- .../thymeleaf/ThymeleafAutoConfiguration.java | 6 ++++ .../thymeleaf/ThymeleafProperties.java | 34 +++++++++++++++++++ ...ymeleafReactiveAutoConfigurationTests.java | 15 ++++++++ ...hymeleafServletAutoConfigurationTests.java | 30 ++++++++++++++++ 4 files changed, 85 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index ab08e499b0..5008c9fad0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -154,6 +154,8 @@ public class ThymeleafAutoConfiguration { public SpringTemplateEngine templateEngine() { SpringTemplateEngine engine = new SpringTemplateEngine(); engine.setEnableSpringELCompiler(this.properties.isEnableSpringElCompiler()); + engine.setRenderHiddenMarkersBeforeCheckboxes( + this.properties.isRenderHiddenMarkersBeforeCheckboxes()); this.templateResolvers.forEach(engine::addTemplateResolver); this.dialects.orderedStream().forEach(engine::addDialect); return engine; @@ -198,6 +200,8 @@ public class ThymeleafAutoConfiguration { resolver.setContentType( appendCharset(this.properties.getServlet().getContentType(), resolver.getCharacterEncoding())); + resolver.setProducePartialOutputWhileProcessing(this.properties + .getServlet().isProducePartialOutputWhileProcessing()); resolver.setExcludedViewNames(this.properties.getExcludedViewNames()); resolver.setViewNames(this.properties.getViewNames()); // This resolver acts as a fallback resolver (e.g. like a @@ -245,6 +249,8 @@ public class ThymeleafAutoConfiguration { public SpringWebFluxTemplateEngine templateEngine() { SpringWebFluxTemplateEngine engine = new SpringWebFluxTemplateEngine(); engine.setEnableSpringELCompiler(this.properties.isEnableSpringElCompiler()); + engine.setRenderHiddenMarkersBeforeCheckboxes( + this.properties.isRenderHiddenMarkersBeforeCheckboxes()); this.templateResolvers.forEach(engine::addTemplateResolver); this.dialects.orderedStream().forEach(engine::addDialect); return engine; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java index 84245030a3..7805e67287 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java @@ -101,6 +101,14 @@ public class ThymeleafProperties { */ private boolean enableSpringElCompiler; + /** + * Whether hidden form inputs acting as markers for checkboxes (which are omitted from + * form submission when unchecked) should be rendered before or after the rendered + * checkbox element itself for better integration with some CSS frameworks. Default is + * "false" (hiddens will be rendered after checkboxes). + */ + private boolean renderHiddenMarkersBeforeCheckboxes; + /** * Whether to enable Thymeleaf view resolution for Web frameworks. */ @@ -206,6 +214,15 @@ public class ThymeleafProperties { this.enableSpringElCompiler = enableSpringElCompiler; } + public boolean isRenderHiddenMarkersBeforeCheckboxes() { + return renderHiddenMarkersBeforeCheckboxes; + } + + public void setRenderHiddenMarkersBeforeCheckboxes( + boolean renderHiddenMarkersBeforeCheckboxes) { + this.renderHiddenMarkersBeforeCheckboxes = renderHiddenMarkersBeforeCheckboxes; + } + public Reactive getReactive() { return this.reactive; } @@ -221,6 +238,14 @@ public class ThymeleafProperties { */ private MimeType contentType = MimeType.valueOf("text/html"); + /** + * Whether Thymeleaf should start sending partial output to the server's output + * buffers as soon as it becomes available (default), or instead wait until + * template processing is finished, keeping all rendered results in memory until + * that moment and sending them to the server's output buffers in a single call. + */ + private boolean producePartialOutputWhileProcessing = true; + public MimeType getContentType() { return this.contentType; } @@ -229,6 +254,15 @@ public class ThymeleafProperties { this.contentType = contentType; } + public boolean isProducePartialOutputWhileProcessing() { + return producePartialOutputWhileProcessing; + } + + public void setProducePartialOutputWhileProcessing( + boolean producePartialOutputWhileProcessing) { + this.producePartialOutputWhileProcessing = producePartialOutputWhileProcessing; + } + } public static class Reactive { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java index bf13da46dd..0575b61015 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java @@ -162,6 +162,21 @@ public class ThymeleafReactiveAutoConfigurationTests { .getEnableSpringELCompiler()).isFalse(); } + @Test + public void overrideRenderHiddenMarkersBeforeCheckboxes() { + load(BaseConfiguration.class, + "spring.thymeleaf.render-hidden-markers-before-checkboxes:true"); + assertThat(this.context.getBean(SpringWebFluxTemplateEngine.class) + .getRenderHiddenMarkersBeforeCheckboxes()).isTrue(); + } + + @Test + public void enableRenderHiddenMarkersBeforeCheckboxesIsDisabledByDefault() { + load(BaseConfiguration.class); + assertThat(this.context.getBean(SpringWebFluxTemplateEngine.class) + .getRenderHiddenMarkersBeforeCheckboxes()).isFalse(); + } + @Test public void templateLocationDoesNotExist() { load(BaseConfiguration.class, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java index eff14e6168..e75a1a1852 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java @@ -107,6 +107,21 @@ public class ThymeleafServletAutoConfigurationTests { assertThat(views.getContentType()).isEqualTo("text/html;charset=UTF-16"); } + @Test + public void overrideDisableProducePartialOutputWhileProcessing() { + load(BaseConfiguration.class, + "spring.thymeleaf.servlet.produce-partial-output-while-processing:false"); + assertThat(this.context.getBean(ThymeleafViewResolver.class) + .getProducePartialOutputWhileProcessing()).isFalse(); + } + + @Test + public void disableProducePartialOutputWhileProcessingIsEnabledByDefault() { + load(BaseConfiguration.class); + assertThat(this.context.getBean(ThymeleafViewResolver.class) + .getProducePartialOutputWhileProcessing()).isTrue(); + } + @Test public void overrideTemplateResolverOrder() { load(BaseConfiguration.class, "spring.thymeleaf.templateResolverOrder:25"); @@ -135,6 +150,21 @@ public class ThymeleafServletAutoConfigurationTests { .getEnableSpringELCompiler()).isFalse(); } + @Test + public void overrideRenderHiddenMarkersBeforeCheckboxes() { + load(BaseConfiguration.class, + "spring.thymeleaf.render-hidden-markers-before-checkboxes:true"); + assertThat(this.context.getBean(SpringTemplateEngine.class) + .getRenderHiddenMarkersBeforeCheckboxes()).isTrue(); + } + + @Test + public void enableRenderHiddenMarkersBeforeCheckboxesIsDisabledByDefault() { + load(BaseConfiguration.class); + assertThat(this.context.getBean(SpringTemplateEngine.class) + .getRenderHiddenMarkersBeforeCheckboxes()).isFalse(); + } + @Test public void templateLocationDoesNotExist() { load(BaseConfiguration.class,