From a3f5816126950c04d321a31f94a0a3a6e4272910 Mon Sep 17 00:00:00 2001 From: blasetti Date: Sat, 28 Sep 2024 17:22:17 +0200 Subject: [PATCH 1/2] Spring MVC model not forwarded #378 --- .../autoconfigure/JteAutoConfiguration.java | 2 +- .../boot/autoconfigure/JteProperties.java | 9 +++++++++ .../boot/autoconfigure/JteViewResolver.java | 5 +++-- .../autoconfigure/JteAutoConfiguration.java | 4 +--- .../boot/autoconfigure/JteProperties.java | 18 ++++++++++++++++++ .../boot/autoconfigure/JteViewResolver.java | 5 +++-- .../spring-configuration-metadata.json | 6 ++++++ 7 files changed, 41 insertions(+), 8 deletions(-) diff --git a/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteAutoConfiguration.java b/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteAutoConfiguration.java index 7fa06274..a6be62e2 100644 --- a/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteAutoConfiguration.java +++ b/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteAutoConfiguration.java @@ -30,7 +30,7 @@ public JteAutoConfiguration(JteProperties jteProperties) { @Bean @ConditionalOnMissingBean(JteViewResolver.class) public JteViewResolver jteViewResolver(TemplateEngine templateEngine) { - return new JteViewResolver(templateEngine, jteProperties.getTemplateSuffix()); + return new JteViewResolver(templateEngine, jteProperties); } diff --git a/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteProperties.java b/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteProperties.java index 7999e1b2..dcfa6606 100644 --- a/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteProperties.java +++ b/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteProperties.java @@ -7,6 +7,7 @@ public class JteProperties { private Boolean usePrecompiledTemplates = false; private String templateLocation = "src/main/jte"; private String templateSuffix = ".jte"; + private boolean exposeRequestAttributes = false; public String getTemplateSuffix() { return templateSuffix; @@ -31,4 +32,12 @@ public Boolean usePreCompiledTemplates() { public void setUsePrecompiledTemplates(Boolean usePrecompiledTemplates) { this.usePrecompiledTemplates = usePrecompiledTemplates; } + + public boolean isExposeRequestAttributes() { + return exposeRequestAttributes; + } + + public void setExposeRequestAttributes(boolean exposeRequestAttributes) { + this.exposeRequestAttributes = exposeRequestAttributes; + } } diff --git a/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteViewResolver.java b/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteViewResolver.java index 7553c78a..5162c18c 100644 --- a/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteViewResolver.java +++ b/jte-spring-boot-starter-2/src/main/java/gg/jte/springframework/boot/autoconfigure/JteViewResolver.java @@ -11,12 +11,13 @@ public class JteViewResolver extends AbstractTemplateViewResolver { private final TemplateEngine templateEngine; - public JteViewResolver(TemplateEngine templateEngine, final String templateSuffix) { + public JteViewResolver(TemplateEngine templateEngine, JteProperties jteProperties) { this.templateEngine = templateEngine; - this.setSuffix(templateSuffix); + this.setSuffix(jteProperties.getTemplateSuffix()); this.setViewClass(JteView.class); this.setContentType(MediaType.TEXT_HTML_VALUE); this.setOrder(Ordered.HIGHEST_PRECEDENCE); + this.setExposeRequestAttributes(jteProperties.isExposeRequestAttributes()); } @Override diff --git a/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteAutoConfiguration.java b/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteAutoConfiguration.java index 87334cc1..8164e7e9 100644 --- a/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteAutoConfiguration.java +++ b/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteAutoConfiguration.java @@ -27,11 +27,9 @@ public JteAutoConfiguration(JteProperties jteProperties) { @Bean @ConditionalOnMissingBean(JteViewResolver.class) public JteViewResolver jteViewResolver(TemplateEngine templateEngine) { - - return new JteViewResolver(templateEngine, jteProperties.getTemplateSuffix()); + return new JteViewResolver(templateEngine, jteProperties); } - @Bean @ConditionalOnMissingBean(TemplateEngine.class) public TemplateEngine jteTemplateEngine() { diff --git a/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteProperties.java b/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteProperties.java index 9fc4de19..89f7534d 100644 --- a/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteProperties.java +++ b/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteProperties.java @@ -8,6 +8,7 @@ public class JteProperties { private boolean developmentMode = false; private String templateLocation = "src/main/jte"; private String templateSuffix = ".jte"; + private boolean exposeRequestAttributes = false; public String getTemplateSuffix() { return templateSuffix; @@ -40,4 +41,21 @@ public boolean isDevelopmentMode() { public void setDevelopmentMode(boolean developmentMode) { this.developmentMode = developmentMode; } + + public boolean isUsePrecompiledTemplates() { + return usePrecompiledTemplates; + } + + public void setUsePrecompiledTemplates(boolean usePrecompiledTemplates) { + this.usePrecompiledTemplates = usePrecompiledTemplates; + } + + public boolean isExposeRequestAttributes() { + return exposeRequestAttributes; + } + + public void setExposeRequestAttributes(boolean exposeRequestAttributes) { + this.exposeRequestAttributes = exposeRequestAttributes; + } + } diff --git a/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteViewResolver.java b/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteViewResolver.java index dcc36d6b..9bf8c57c 100644 --- a/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteViewResolver.java +++ b/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure/JteViewResolver.java @@ -10,12 +10,13 @@ public class JteViewResolver extends AbstractTemplateViewResolver { private final TemplateEngine templateEngine; - public JteViewResolver(TemplateEngine templateEngine, final String templateSuffix) { + public JteViewResolver(TemplateEngine templateEngine, JteProperties jteProperties) { this.templateEngine = templateEngine; - this.setSuffix(templateSuffix); + this.setSuffix(jteProperties.getTemplateSuffix()); this.setViewClass(JteView.class); this.setContentType(MediaType.TEXT_HTML_VALUE); this.setOrder(Ordered.HIGHEST_PRECEDENCE); + this.setExposeRequestAttributes(jteProperties.isExposeRequestAttributes()); } @Override diff --git a/jte-spring-boot-starter-3/src/main/resources/META-INF/spring-configuration-metadata.json b/jte-spring-boot-starter-3/src/main/resources/META-INF/spring-configuration-metadata.json index ade0e3ac..baa6d807 100644 --- a/jte-spring-boot-starter-3/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/jte-spring-boot-starter-3/src/main/resources/META-INF/spring-configuration-metadata.json @@ -30,6 +30,12 @@ "type": "java.lang.String", "description": "You can configure the file suffix of jte templates the compiler resolves", "sourceType": "gg.jte.springframework.boot.autoconfigure.JteProperties" + }, + { + "name": "gg.jte.exposeRequestAttributes", + "type": "java.lang.Boolean", + "description": "Set whether all request attributes should be added to the model prior to merging with the template", + "sourceType": "gg.jte.springframework.boot.autoconfigure.JteProperties" } ], "hints": [] From 269cdcb7e98ebf57c412ba6e495cf8beffae505a Mon Sep 17 00:00:00 2001 From: Andreas Hager Date: Tue, 8 Oct 2024 19:45:41 +0200 Subject: [PATCH 2/2] Update jte-spring-boot-starter-3/src/main/resources/META-INF/spring-configuration-metadata.json Co-authored-by: Frederik Hahne --- .../main/resources/META-INF/spring-configuration-metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jte-spring-boot-starter-3/src/main/resources/META-INF/spring-configuration-metadata.json b/jte-spring-boot-starter-3/src/main/resources/META-INF/spring-configuration-metadata.json index baa6d807..94e252a5 100644 --- a/jte-spring-boot-starter-3/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/jte-spring-boot-starter-3/src/main/resources/META-INF/spring-configuration-metadata.json @@ -32,7 +32,7 @@ "sourceType": "gg.jte.springframework.boot.autoconfigure.JteProperties" }, { - "name": "gg.jte.exposeRequestAttributes", + "name": "gg.jte.expose-request-attributes", "type": "java.lang.Boolean", "description": "Set whether all request attributes should be added to the model prior to merging with the template", "sourceType": "gg.jte.springframework.boot.autoconfigure.JteProperties"