Skip to content

Commit 91a1866

Browse files
committed
Replace Tiles with Thymeleaf layout
1 parent 6b958aa commit 91a1866

File tree

23 files changed

+157
-457
lines changed

23 files changed

+157
-457
lines changed

booking-mvc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<dependency>
7373
<groupId>org.thymeleaf</groupId>
7474
<artifactId>thymeleaf</artifactId>
75-
<version>2.1.5.RELEASE</version>
75+
<version>3.1.0.M1</version>
7676
</dependency>
7777
<dependency>
7878
<groupId>org.thymeleaf</groupId>

booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public HotelsController(BookingService bookingService) {
2121
}
2222

2323
@GetMapping("/hotels/search")
24-
public void search(SearchCriteria searchCriteria, Principal currentUser, Model model) {
24+
public void search(@SuppressWarnings("unused") SearchCriteria searchCriteria, Principal currentUser, Model model) {
2525
if (currentUser != null) {
2626
List<Booking> booking = bookingService.findBookings(currentUser.getName());
2727
model.addAttribute(booking);

booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/SecurityConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
66
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
77
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
8+
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
89

910
@Configuration
1011
@EnableWebSecurity
@@ -20,7 +21,7 @@ protected void configure(HttpSecurity http) throws Exception {
2021
.failureUrl("/login?login_error=1")
2122
.and()
2223
.logout()
23-
.logoutUrl("/logout")
24+
.logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET"))
2425
.logoutSuccessUrl("/logoutSuccess");
2526
}
2627

booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebFlowConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public FlowBuilderServices flowBuilderServices() {
4545
@Bean
4646
public MvcViewFactoryCreator mvcViewFactoryCreator() {
4747
MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator();
48-
factoryCreator.setViewResolvers(Collections.singletonList(this.webMvcConfig.tilesViewResolver()));
48+
factoryCreator.setViewResolvers(Collections.singletonList(this.webMvcConfig.thymeleafViewResolver()));
4949
factoryCreator.setUseSpringBeanBinding(true);
5050
return factoryCreator;
5151
}

booking-mvc/src/main/java/org/springframework/webflow/samples/booking/config/WebMvcConfig.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,43 @@
33
import java.util.LinkedHashSet;
44
import java.util.Set;
55

6+
import jakarta.servlet.ServletContext;
7+
import org.thymeleaf.dialect.IDialect;
8+
import org.thymeleaf.extras.springsecurity6.dialect.SpringSecurityDialect;
9+
import org.thymeleaf.spring6.SpringTemplateEngine;
10+
import org.thymeleaf.spring6.view.AjaxThymeleafViewResolver;
11+
import org.thymeleaf.spring6.view.FlowAjaxThymeleafView;
12+
import org.thymeleaf.templateresolver.WebApplicationTemplateResolver;
13+
import org.thymeleaf.web.IWebApplication;
14+
import org.thymeleaf.web.servlet.JakartaServletWebApplication;
15+
616
import org.springframework.beans.factory.annotation.Autowired;
717
import org.springframework.context.annotation.Bean;
818
import org.springframework.context.annotation.Configuration;
19+
import org.springframework.web.context.ServletContextAware;
920
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
1021
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
1122
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
1223
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
13-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
24+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
1425
import org.springframework.webflow.mvc.servlet.FlowHandlerAdapter;
1526
import org.springframework.webflow.mvc.servlet.FlowHandlerMapping;
1627
import org.springframework.webflow.samples.booking.BookingFlowHandler;
17-
import org.thymeleaf.dialect.IDialect;
18-
import org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect;
19-
import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;
20-
import org.thymeleaf.extras.tiles2.dialect.TilesDialect;
21-
import org.thymeleaf.extras.tiles2.spring4.web.configurer.ThymeleafTilesConfigurer;
22-
import org.thymeleaf.extras.tiles2.spring4.web.view.FlowAjaxThymeleafTilesView;
23-
import org.thymeleaf.spring4.SpringTemplateEngine;
24-
import org.thymeleaf.spring4.view.AjaxThymeleafViewResolver;
25-
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
2628

2729
@EnableWebMvc
2830
@Configuration
29-
public class WebMvcConfig extends WebMvcConfigurerAdapter {
31+
public class WebMvcConfig implements WebMvcConfigurer, ServletContextAware {
3032

3133
@Autowired
3234
private WebFlowConfig webFlowConfig;
3335

36+
private ServletContext servletContext;
37+
38+
@Override
39+
public void setServletContext(ServletContext servletContext) {
40+
this.servletContext = servletContext;
41+
}
42+
3443
@Override
3544
public void addResourceHandlers(ResourceHandlerRegistry registry) {
3645
registry.addResourceHandler("/resources/**").addResourceLocations("/", "classpath:/META-INF/web-resources/");
@@ -70,20 +79,18 @@ public BookingFlowHandler BookingFlowHandler() {
7079
}
7180

7281
@Bean
73-
public AjaxThymeleafViewResolver tilesViewResolver() {
82+
public AjaxThymeleafViewResolver thymeleafViewResolver() {
7483
AjaxThymeleafViewResolver viewResolver = new AjaxThymeleafViewResolver();
75-
viewResolver.setViewClass(FlowAjaxThymeleafTilesView.class);
84+
viewResolver.setViewClass(FlowAjaxThymeleafView.class);
7685
viewResolver.setTemplateEngine(templateEngine());
7786
return viewResolver;
7887
}
7988

8089
@Bean
8190
public SpringTemplateEngine templateEngine(){
8291

83-
Set<IDialect> dialects = new LinkedHashSet<IDialect>();
84-
dialects.add(new TilesDialect());
92+
Set<IDialect> dialects = new LinkedHashSet<>();
8593
dialects.add(new SpringSecurityDialect());
86-
dialects.add(new ConditionalCommentsDialect());
8794

8895
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
8996
templateEngine.setTemplateResolver(templateResolver());
@@ -92,18 +99,13 @@ public SpringTemplateEngine templateEngine(){
9299
}
93100

94101
@Bean
95-
public ServletContextTemplateResolver templateResolver() {
96-
ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
97-
templateResolver.setPrefix("/WEB-INF");
98-
templateResolver.setTemplateMode("HTML5");
99-
return templateResolver;
100-
}
101-
102-
@Bean
103-
public ThymeleafTilesConfigurer tilesConfigurer() {
104-
ThymeleafTilesConfigurer configurer = new ThymeleafTilesConfigurer();
105-
configurer.setDefinitions("/WEB-INF/**/views.xml");
106-
return configurer;
102+
public WebApplicationTemplateResolver templateResolver() {
103+
IWebApplication application = JakartaServletWebApplication.buildApplication(this.servletContext);
104+
WebApplicationTemplateResolver resolver = new WebApplicationTemplateResolver(application);
105+
resolver.setPrefix("/WEB-INF/");
106+
resolver.setSuffix(".html");
107+
resolver.setTemplateMode("HTML5");
108+
return resolver;
107109
}
108110

109111
}

booking-mvc/src/main/resources/log4j2.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Loggers>
99
<Logger name="org.springframework.samples" level="debug" />
1010
<Logger name="org.springframework.web" level="debug" />
11+
<Logger name="org.thymeleaf.spring6" level="debug" />
1112
<Root level="info">
1213
<AppenderRef ref="Console" />
1314
</Root>

booking-mvc/src/main/webapp/WEB-INF/hotels/booking/booking-flow.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<evaluate expression="bookingService.createBooking(hotelId, currentUser.name)" result="flowScope.booking" />
1414
</on-start>
1515

16-
<view-state id="enterBookingDetails" model="booking">
16+
<view-state id="enterBookingDetails" model="booking" view="/hotels/booking/enterBookingDetails.html">
1717
<binder>
1818
<binding property="checkinDate" />
1919
<binding property="checkoutDate" />
@@ -32,7 +32,7 @@
3232
<transition on="cancel" to="cancel" bind="false" />
3333
</view-state>
3434

35-
<view-state id="reviewBooking">
35+
<view-state id="reviewBooking" view="/hotels/booking/reviewBooking.html">
3636
<on-render>
3737
<render fragments="body" />
3838
</on-render>

booking-mvc/src/main/webapp/WEB-INF/hotels/booking/enterBookingDetails.html

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,36 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml"
33
xmlns:th="http://www.thymeleaf.org"
4-
xmlns:tiles="http://www.thymeleaf.org"
5-
xmlns:sec="http://www.thymeleaf.org"
64
lang="en">
75

8-
<head>
6+
<head th:replace="layouts/standard.html :: //head">
97

108
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
11-
<!-- This <head> section is only used for static prototyping purposes. At runtime, -->
12-
<!-- Tiles will only use the body fragment defined with tiles:fragment="content", -->
13-
<!-- as specified at the corresponding views.xml file. -->
9+
<!-- This <head> section is only used for static prototyping purposes. -->
1410
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
1511

1612
<title>Spring Travel: Spring MVC and Web Flow Reference Application</title>
1713
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
18-
19-
<link rel="stylesheet" type="text/css" media="screen, projection"
14+
15+
<link rel="stylesheet" type="text/css" media="screen, projection"
2016
href="../../../styles/blueprint/screen.css" />
21-
22-
<link rel="stylesheet" type="text/css" media="print"
17+
18+
<link rel="stylesheet" type="text/css" media="print"
2319
href="../../../styles/blueprint/print.css" />
24-
20+
2521
<!--[if lt IE 8]>
26-
<link rel="stylesheet" type="text/css" media="screen, projection"
27-
href="../../../styles/blueprint/ie.css" />
22+
<link rel="stylesheet" type="text/css" media="screen, projection"
23+
href="../../../styles/blueprint/ie.css" />
2824
<![endif]-->
29-
30-
<link rel="stylesheet" type="text/css" media="screen"
31-
href="../../../styles/booking.css" />
3225

33-
34-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
35-
<!-- Some styles and scripts are served from spring-js-resources-{ver}.jar at -->
36-
<!-- runtime. Therefore not available for static prototyping. See the -->
37-
<!-- layouts/standard.html template file for detail. -->
38-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
39-
40-
</head>
26+
<link rel="stylesheet" type="text/css" media="screen" href="../../../styles/booking.css" />
4127

42-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
43-
<!-- START of the content to be included in the execution result. -->
44-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
45-
<!-- Only the markup inside this <body> would be required in this -->
46-
<!-- template if no static prototyping was intended. -->
47-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
48-
<body tiles:fragment="content">
28+
</head>
4929

30+
<body th:replace="layouts/standard.html :: body(~{::bodyContent})">
5031

5132

52-
<div id="bookingForm">
33+
<div th:fragment="bodyContent">
5334

5435
<div class="span-5">
5536

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,33 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml"
33
xmlns:th="http://www.thymeleaf.org"
4-
xmlns:tiles="http://www.thymeleaf.org"
5-
xmlns:sec="http://www.thymeleaf.org"
64
lang="en">
75

8-
<head>
6+
<head th:replace="layouts/standard.html :: //head">
97

108
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
11-
<!-- This <head> section is only used for static prototyping purposes. At runtime, -->
12-
<!-- Tiles will only use the body fragment defined with tiles:fragment="content", -->
13-
<!-- as specified at the corresponding views.xml file. -->
9+
<!-- This <head> section is only used for static prototyping purposes. -->
1410
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
1511

1612
<title>Spring Travel: Spring MVC and Web Flow Reference Application</title>
1713
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
18-
19-
<link rel="stylesheet" type="text/css" media="screen, projection"
14+
15+
<link rel="stylesheet" type="text/css" media="screen, projection"
2016
href="../../../styles/blueprint/screen.css" />
21-
22-
<link rel="stylesheet" type="text/css" media="print"
17+
18+
<link rel="stylesheet" type="text/css" media="print"
2319
href="../../../styles/blueprint/print.css" />
24-
20+
2521
<!--[if lt IE 8]>
26-
<link rel="stylesheet" type="text/css" media="screen, projection"
27-
href="../../../styles/blueprint/ie.css" />
22+
<link rel="stylesheet" type="text/css" media="screen, projection"
23+
href="../../../styles/blueprint/ie.css" />
2824
<![endif]-->
29-
30-
<link rel="stylesheet" type="text/css" media="screen"
31-
href="../../../styles/booking.css" />
3225

33-
34-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
35-
<!-- Some styles and scripts are served from spring-js-resources-{ver}.jar at -->
36-
<!-- runtime. Therefore not available for static prototyping. See the -->
37-
<!-- layouts/standard.html template file for detail. -->
38-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
39-
40-
</head>
41-
42-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
43-
<!-- START of the content to be included in the execution result. -->
44-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
45-
<!-- Only the markup inside this <body> would be required in this -->
46-
<!-- template if no static prototyping was intended. -->
47-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
48-
<body tiles:fragment="content">
26+
<link rel="stylesheet" type="text/css" media="screen" href="../../../styles/booking.css" />
4927

28+
</head>
5029

30+
<body th:replace="layouts/standard.html :: body(~{::#messages})">
5131

5232

5333
<div id="messages">
@@ -58,8 +38,5 @@
5838

5939

6040
</body>
61-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
62-
<!-- END of the content to be included in the execution result -->
63-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
6441

6542
</html>

booking-mvc/src/main/webapp/WEB-INF/hotels/booking/reviewBooking.html

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,35 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml"
33
xmlns:th="http://www.thymeleaf.org"
4-
xmlns:tiles="http://www.thymeleaf.org"
5-
xmlns:sec="http://www.thymeleaf.org"
64
lang="en">
75

8-
<head>
6+
<head th:replace="layouts/standard.html :: //head">
97

108
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
11-
<!-- This <head> section is only used for static prototyping purposes. At runtime, -->
12-
<!-- Tiles will only use the body fragment defined with tiles:fragment="content", -->
13-
<!-- as specified at the corresponding views.xml file. -->
9+
<!-- This <head> section is only used for static prototyping purposes. -->
1410
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
1511

1612
<title>Spring Travel: Spring MVC and Web Flow Reference Application</title>
1713
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
18-
19-
<link rel="stylesheet" type="text/css" media="screen, projection"
14+
15+
<link rel="stylesheet" type="text/css" media="screen, projection"
2016
href="../../../styles/blueprint/screen.css" />
21-
22-
<link rel="stylesheet" type="text/css" media="print"
17+
18+
<link rel="stylesheet" type="text/css" media="print"
2319
href="../../../styles/blueprint/print.css" />
24-
20+
2521
<!--[if lt IE 8]>
26-
<link rel="stylesheet" type="text/css" media="screen, projection"
27-
href="../../../styles/blueprint/ie.css" />
22+
<link rel="stylesheet" type="text/css" media="screen, projection"
23+
href="../../../styles/blueprint/ie.css" />
2824
<![endif]-->
29-
30-
<link rel="stylesheet" type="text/css" media="screen"
31-
href="../../../styles/booking.css" />
3225

33-
34-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
35-
<!-- Some styles and scripts are served from spring-js-resources-{ver}.jar at -->
36-
<!-- runtime. Therefore not available for static prototyping. See the -->
37-
<!-- layouts/standard.html template file for detail. -->
38-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
39-
40-
</head>
41-
42-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
43-
<!-- START of the content to be included in the execution result. -->
44-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
45-
<!-- Only the markup inside this <body> would be required in this -->
46-
<!-- template if no static prototyping was intended. -->
47-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
48-
<body tiles:fragment="content">
26+
<link rel="stylesheet" type="text/css" media="screen" href="../../../styles/booking.css" />
4927

28+
</head>
5029

30+
<body th:replace="layouts/standard.html :: body(~{::bodyContent})">
5131

52-
<div id="bookingForm">
32+
<div th:fragment="bodyContent">
5333

5434
<div class="span-5">
5535

@@ -126,10 +106,6 @@ <h3 th:text="${booking.hotel.name}">The Herb Plaza</h3>
126106

127107
</div>
128108

129-
130109
</body>
131-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
132-
<!-- END of the content to be included in the execution result -->
133-
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
134110

135111
</html>

0 commit comments

Comments
 (0)