From 91a1866e618bd3a70bb1a622aaa8cdedd296cfa3 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 18 Jul 2022 09:31:19 +0100 Subject: [PATCH] Replace Tiles with Thymeleaf layout --- booking-mvc/pom.xml | 2 +- .../samples/booking/HotelsController.java | 2 +- .../booking/config/SecurityConfig.java | 3 +- .../samples/booking/config/WebFlowConfig.java | 2 +- .../samples/booking/config/WebMvcConfig.java | 58 ++++++++++--------- booking-mvc/src/main/resources/log4j2.xml | 1 + .../WEB-INF/hotels/booking/booking-flow.xml | 4 +- .../hotels/booking/enterBookingDetails.html | 53 ++++++----------- .../WEB-INF/hotels/booking/messages.html | 55 +++++------------- .../WEB-INF/hotels/booking/reviewBooking.html | 58 ++++++------------- .../webapp/WEB-INF/hotels/booking/views.xml | 16 ----- .../webapp/WEB-INF/hotels/bookingsTable.html | 33 ++--------- .../src/main/webapp/WEB-INF/hotels/list.html | 44 +++----------- .../main/webapp/WEB-INF/hotels/search.html | 37 +++--------- .../webapp/WEB-INF/hotels/searchForm.html | 31 +++------- .../src/main/webapp/WEB-INF/hotels/show.html | 55 ++++++------------ .../src/main/webapp/WEB-INF/hotels/views.xml | 21 ------- .../src/main/webapp/WEB-INF/intro.html | 34 ++--------- .../main/webapp/WEB-INF/layouts/standard.html | 13 +---- .../src/main/webapp/WEB-INF/layouts/views.xml | 11 ---- .../src/main/webapp/WEB-INF/login.html | 52 ++++++----------- .../main/webapp/WEB-INF/logoutSuccess.html | 55 ++++++------------ booking-mvc/src/main/webapp/WEB-INF/views.xml | 20 ------- 23 files changed, 180 insertions(+), 480 deletions(-) delete mode 100644 booking-mvc/src/main/webapp/WEB-INF/hotels/booking/views.xml delete mode 100644 booking-mvc/src/main/webapp/WEB-INF/hotels/views.xml delete mode 100644 booking-mvc/src/main/webapp/WEB-INF/layouts/views.xml delete mode 100644 booking-mvc/src/main/webapp/WEB-INF/views.xml diff --git a/booking-mvc/pom.xml b/booking-mvc/pom.xml index ab30257..7c6f83e 100644 --- a/booking-mvc/pom.xml +++ b/booking-mvc/pom.xml @@ -72,7 +72,7 @@ org.thymeleaf thymeleaf - 2.1.5.RELEASE + 3.1.0.M1 org.thymeleaf diff --git a/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java b/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java index 5a11404..3e5da3c 100644 --- a/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java +++ b/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java @@ -21,7 +21,7 @@ public class HotelsController { } @GetMapping("/hotels/search") - public void search(SearchCriteria searchCriteria, Principal currentUser, Model model) { + public void search(@SuppressWarnings("unused") SearchCriteria searchCriteria, Principal currentUser, Model model) { if (currentUser != null) { List booking = bookingService.findBookings(currentUser.getName()); model.addAttribute(booking); diff --git a/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/SecurityConfig.java b/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/SecurityConfig.java index c31f82b..6d496b0 100644 --- a/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/SecurityConfig.java +++ b/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/SecurityConfig.java @@ -5,6 +5,7 @@ import org.springframework.security.config.annotation.authentication.builders.Au import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @Configuration @EnableWebSecurity @@ -20,7 +21,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .failureUrl("/login?login_error=1") .and() .logout() - .logoutUrl("/logout") + .logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET")) .logoutSuccessUrl("/logoutSuccess"); } diff --git a/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebFlowConfig.java b/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebFlowConfig.java index 2fe49a3..31a979f 100644 --- a/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebFlowConfig.java +++ b/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebFlowConfig.java @@ -45,7 +45,7 @@ public class WebFlowConfig extends AbstractFlowConfiguration { @Bean public MvcViewFactoryCreator mvcViewFactoryCreator() { MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator(); - factoryCreator.setViewResolvers(Collections.singletonList(this.webMvcConfig.tilesViewResolver())); + factoryCreator.setViewResolvers(Collections.singletonList(this.webMvcConfig.thymeleafViewResolver())); factoryCreator.setUseSpringBeanBinding(true); return factoryCreator; } diff --git a/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebMvcConfig.java b/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebMvcConfig.java index 9c4980b..4851e13 100644 --- a/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebMvcConfig.java +++ b/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebMvcConfig.java @@ -3,34 +3,43 @@ package org.springframework.webflow.samples.booking.config; import java.util.LinkedHashSet; import java.util.Set; +import jakarta.servlet.ServletContext; +import org.thymeleaf.dialect.IDialect; +import org.thymeleaf.extras.springsecurity6.dialect.SpringSecurityDialect; +import org.thymeleaf.spring6.SpringTemplateEngine; +import org.thymeleaf.spring6.view.AjaxThymeleafViewResolver; +import org.thymeleaf.spring6.view.FlowAjaxThymeleafView; +import org.thymeleaf.templateresolver.WebApplicationTemplateResolver; +import org.thymeleaf.web.IWebApplication; +import org.thymeleaf.web.servlet.JakartaServletWebApplication; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.context.ServletContextAware; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.webflow.mvc.servlet.FlowHandlerAdapter; import org.springframework.webflow.mvc.servlet.FlowHandlerMapping; import org.springframework.webflow.samples.booking.BookingFlowHandler; -import org.thymeleaf.dialect.IDialect; -import org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect; -import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect; -import org.thymeleaf.extras.tiles2.dialect.TilesDialect; -import org.thymeleaf.extras.tiles2.spring4.web.configurer.ThymeleafTilesConfigurer; -import org.thymeleaf.extras.tiles2.spring4.web.view.FlowAjaxThymeleafTilesView; -import org.thymeleaf.spring4.SpringTemplateEngine; -import org.thymeleaf.spring4.view.AjaxThymeleafViewResolver; -import org.thymeleaf.templateresolver.ServletContextTemplateResolver; @EnableWebMvc @Configuration -public class WebMvcConfig extends WebMvcConfigurerAdapter { +public class WebMvcConfig implements WebMvcConfigurer, ServletContextAware { @Autowired private WebFlowConfig webFlowConfig; + private ServletContext servletContext; + + @Override + public void setServletContext(ServletContext servletContext) { + this.servletContext = servletContext; + } + @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/", "classpath:/META-INF/web-resources/"); @@ -70,9 +79,9 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { } @Bean - public AjaxThymeleafViewResolver tilesViewResolver() { + public AjaxThymeleafViewResolver thymeleafViewResolver() { AjaxThymeleafViewResolver viewResolver = new AjaxThymeleafViewResolver(); - viewResolver.setViewClass(FlowAjaxThymeleafTilesView.class); + viewResolver.setViewClass(FlowAjaxThymeleafView.class); viewResolver.setTemplateEngine(templateEngine()); return viewResolver; } @@ -80,10 +89,8 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { @Bean public SpringTemplateEngine templateEngine(){ - Set dialects = new LinkedHashSet(); - dialects.add(new TilesDialect()); + Set dialects = new LinkedHashSet<>(); dialects.add(new SpringSecurityDialect()); - dialects.add(new ConditionalCommentsDialect()); SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.setTemplateResolver(templateResolver()); @@ -92,18 +99,13 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { } @Bean - public ServletContextTemplateResolver templateResolver() { - ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); - templateResolver.setPrefix("/WEB-INF"); - templateResolver.setTemplateMode("HTML5"); - return templateResolver; - } - - @Bean - public ThymeleafTilesConfigurer tilesConfigurer() { - ThymeleafTilesConfigurer configurer = new ThymeleafTilesConfigurer(); - configurer.setDefinitions("/WEB-INF/**/views.xml"); - return configurer; + public WebApplicationTemplateResolver templateResolver() { + IWebApplication application = JakartaServletWebApplication.buildApplication(this.servletContext); + WebApplicationTemplateResolver resolver = new WebApplicationTemplateResolver(application); + resolver.setPrefix("/WEB-INF/"); + resolver.setSuffix(".html"); + resolver.setTemplateMode("HTML5"); + return resolver; } } diff --git a/booking-mvc/src/main/resources/log4j2.xml b/booking-mvc/src/main/resources/log4j2.xml index bb09f49..22aa0ba 100644 --- a/booking-mvc/src/main/resources/log4j2.xml +++ b/booking-mvc/src/main/resources/log4j2.xml @@ -8,6 +8,7 @@ + diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/booking-flow.xml b/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/booking-flow.xml index d166884..be94c71 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/booking-flow.xml +++ b/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/booking-flow.xml @@ -13,7 +13,7 @@ - + @@ -32,7 +32,7 @@ - + diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/enterBookingDetails.html b/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/enterBookingDetails.html index 83c00ef..db4f37d 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/enterBookingDetails.html +++ b/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/enterBookingDetails.html @@ -1,55 +1,36 @@ - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - + - -
+
diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/messages.html b/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/messages.html index 7d9638c..c1064d8 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/messages.html +++ b/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/messages.html @@ -1,53 +1,33 @@ - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - +
@@ -58,8 +38,5 @@ - - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/reviewBooking.html b/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/reviewBooking.html index a54a00a..ef39373 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/reviewBooking.html +++ b/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/reviewBooking.html @@ -1,55 +1,35 @@ - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - + - - -
+
@@ -126,10 +106,6 @@
- - - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/views.xml b/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/views.xml deleted file mode 100644 index a085f66..0000000 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/views.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/bookingsTable.html b/booking-mvc/src/main/webapp/WEB-INF/hotels/bookingsTable.html index d6bbc21..abfd1ce 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/bookingsTable.html +++ b/booking-mvc/src/main/webapp/WEB-INF/hotels/bookingsTable.html @@ -1,16 +1,13 @@ - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application @@ -26,29 +23,15 @@ - - - - - - - - - + + - - - - - - - + -
+

Current Hotel Bookings

@@ -87,10 +70,6 @@
- - - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/list.html b/booking-mvc/src/main/webapp/WEB-INF/hotels/list.html index 45e8150..d60087e 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/list.html +++ b/booking-mvc/src/main/webapp/WEB-INF/hotels/list.html @@ -1,16 +1,12 @@ - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application @@ -26,28 +22,14 @@ - - - - - - - - + - - - - - - - - + +

Hotel Results

@@ -55,14 +37,12 @@ Change Search

@@ -100,13 +80,11 @@ Previous Results
@@ -115,13 +93,11 @@ More Results
@@ -130,10 +106,8 @@
+
- - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/search.html b/booking-mvc/src/main/webapp/WEB-INF/hotels/search.html index 35f5f0a..a1cc521 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/search.html +++ b/booking-mvc/src/main/webapp/WEB-INF/hotels/search.html @@ -1,16 +1,12 @@ - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application @@ -27,42 +23,25 @@ href="../../styles/blueprint/ie.css" /> - + - - - - - - - - - - - - - - + +
- -
+
A search form will go here. See it at searchForm.html.
-
+
A table with the current hotel bookings will go here. See it at bookingsTable.html.
- +
- - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/searchForm.html b/booking-mvc/src/main/webapp/WEB-INF/hotels/searchForm.html index f337b8c..249c313 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/searchForm.html +++ b/booking-mvc/src/main/webapp/WEB-INF/hotels/searchForm.html @@ -5,12 +5,10 @@ xmlns:sec="http://www.thymeleaf.org" lang="en"> - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application @@ -26,27 +24,14 @@ - - - - - - - - - + + - - - - - - - + +

Search Hotels

@@ -86,10 +71,8 @@ +
- - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/show.html b/booking-mvc/src/main/webapp/WEB-INF/hotels/show.html index e4f6489..421e05e 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/show.html +++ b/booking-mvc/src/main/webapp/WEB-INF/hotels/show.html @@ -5,49 +5,33 @@ xmlns:sec="http://www.thymeleaf.org" lang="en"> - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - + +

The Herb Plaza

@@ -71,11 +55,8 @@
- +
- - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/hotels/views.xml b/booking-mvc/src/main/webapp/WEB-INF/hotels/views.xml deleted file mode 100644 index a697ace..0000000 --- a/booking-mvc/src/main/webapp/WEB-INF/hotels/views.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/intro.html b/booking-mvc/src/main/webapp/WEB-INF/intro.html index f697b58..233e1a4 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/intro.html +++ b/booking-mvc/src/main/webapp/WEB-INF/intro.html @@ -1,16 +1,12 @@ - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application @@ -23,31 +19,17 @@ href="../styles/blueprint/print.css" /> - + - - - - - - - - - - - - - - + -
+

Welcome to Spring Travel

This sample demonstrates how to use Spring MVC and Spring Web Flow together with Thymeleaf and Tiles. @@ -77,10 +59,6 @@

- - - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.html b/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.html index fb1c2de..8706d91 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.html +++ b/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.html @@ -1,7 +1,6 @@ @@ -41,7 +40,7 @@ - +
@@ -77,16 +76,10 @@

-
+
- - - - - - BODY PAGE GOES HERE! - +
diff --git a/booking-mvc/src/main/webapp/WEB-INF/layouts/views.xml b/booking-mvc/src/main/webapp/WEB-INF/layouts/views.xml deleted file mode 100644 index dac7eb1..0000000 --- a/booking-mvc/src/main/webapp/WEB-INF/layouts/views.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/login.html b/booking-mvc/src/main/webapp/WEB-INF/login.html index d67df11..9f8b5c7 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/login.html +++ b/booking-mvc/src/main/webapp/WEB-INF/login.html @@ -1,52 +1,35 @@ - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - + +

Valid username/passwords are:

@@ -127,6 +110,7 @@
+
diff --git a/booking-mvc/src/main/webapp/WEB-INF/logoutSuccess.html b/booking-mvc/src/main/webapp/WEB-INF/logoutSuccess.html index b8552d5..00f4f08 100644 --- a/booking-mvc/src/main/webapp/WEB-INF/logoutSuccess.html +++ b/booking-mvc/src/main/webapp/WEB-INF/logoutSuccess.html @@ -2,53 +2,35 @@ - + - - - + Spring Travel: Spring MVC and Web Flow Reference Application - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - + - -
+

Logout

You have successfully logged out.


@@ -57,8 +39,5 @@ - - - diff --git a/booking-mvc/src/main/webapp/WEB-INF/views.xml b/booking-mvc/src/main/webapp/WEB-INF/views.xml deleted file mode 100644 index e1ffede..0000000 --- a/booking-mvc/src/main/webapp/WEB-INF/views.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - -