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`
pull/14859/head
Daniel Fernández 6 years ago committed by Brian Clozel
parent 98d95268e1
commit 56c1247bbb

@ -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;

@ -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 {

@ -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,

@ -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,

Loading…
Cancel
Save