Skip to content

Commit 659cf0f

Browse files
authored
Merge pull request eugenp#4497 from eugenp/update-tiles
move tiles to mvc simple
2 parents 122a43a + 218c258 commit 659cf0f

18 files changed

Lines changed: 186 additions & 294 deletions

File tree

‎pom.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@
183183
<module>spring-mvc-forms-jsp</module>
184184
<module>spring-mvc-forms-thymeleaf</module>
185185
<module>spring-mvc-java</module>
186-
<module>spring-mvc-tiles</module>
187186
<module>spring-mvc-velocity</module>
188187
<module>spring-mvc-webflow</module>
189188
<module>spring-mvc-xml</module>

‎spring-mvc-simple/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
- [Template Engines for Spring](http://www.baeldung.com/spring-template-engines)
55
- [Spring 5 and Servlet 4 – The PushBuilder](http://www.baeldung.com/spring-5-push)
66
- [Servlet Redirect vs Forward](http://www.baeldung.com/servlet-redirect-forward)
7+
- [Apache Tiles Integration with Spring MVC](http://www.baeldung.com/spring-mvc-apache-tiles)

‎spring-mvc-simple/pom.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888
<artifactId>spring-jade4j</artifactId>
8989
<version>${jade.version}</version>
9090
</dependency>
91+
92+
<dependency>
93+
<groupId>org.apache.tiles</groupId>
94+
<artifactId>tiles-jsp</artifactId>
95+
<version>${apache-tiles.version}</version>
96+
</dependency>
9197

9298
<!--Testing -->
9399
<dependency>
@@ -181,6 +187,7 @@
181187
<scribejava.version>5.1.0</scribejava.version>
182188
<json.version>20180130</json.version>
183189
<spring-oxm.version>5.0.2.RELEASE</spring-oxm.version>
190+
<apache-tiles.version>3.0.8</apache-tiles.version>
184191
</properties>
185192

186193
</project>

spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationConfiguration.java renamed to spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
package com.baeldung.tiles.springmvc;
2-
3-
import org.springframework.context.annotation.Bean;
4-
import org.springframework.context.annotation.ComponentScan;
5-
import org.springframework.context.annotation.Configuration;
6-
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
7-
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
8-
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
9-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
10-
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
11-
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
12-
13-
@Configuration
14-
@EnableWebMvc
15-
@ComponentScan(basePackages = "com.baeldung.tiles.springmvc")
16-
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
17-
18-
/**
19-
* Configure TilesConfigurer.
20-
*/
21-
@Bean
22-
public TilesConfigurer tilesConfigurer() {
23-
TilesConfigurer tilesConfigurer = new TilesConfigurer();
24-
tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/views/**/tiles.xml" });
25-
tilesConfigurer.setCheckRefresh(true);
26-
return tilesConfigurer;
27-
}
28-
29-
/**
30-
* Configure ViewResolvers to deliver views.
31-
*/
32-
@Override
33-
public void configureViewResolvers(ViewResolverRegistry registry) {
34-
TilesViewResolver viewResolver = new TilesViewResolver();
35-
registry.viewResolver(viewResolver);
36-
}
37-
38-
/**
39-
* Configure ResourceHandlers to serve static resources
40-
*/
41-
42-
@Override
43-
public void addResourceHandlers(ResourceHandlerRegistry registry) {
44-
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
45-
}
46-
47-
}
1+
package com.baeldung.spring.configuration;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
7+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
8+
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
9+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
10+
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
11+
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
12+
13+
@Configuration
14+
@EnableWebMvc
15+
@ComponentScan(basePackages = "com.baeldung.spring.controller.tiles")
16+
public class TilesApplicationConfiguration implements WebMvcConfigurer {
17+
18+
/**
19+
* Configure TilesConfigurer.
20+
*/
21+
@Bean
22+
public TilesConfigurer tilesConfigurer() {
23+
TilesConfigurer tilesConfigurer = new TilesConfigurer();
24+
tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/views/**/tiles.xml" });
25+
tilesConfigurer.setCheckRefresh(true);
26+
return tilesConfigurer;
27+
}
28+
29+
/**
30+
* Configure ViewResolvers to deliver views.
31+
*/
32+
@Override
33+
public void configureViewResolvers(ViewResolverRegistry registry) {
34+
TilesViewResolver viewResolver = new TilesViewResolver();
35+
registry.viewResolver(viewResolver);
36+
}
37+
38+
/**
39+
* Configure ResourceHandlers to serve static resources
40+
*/
41+
42+
@Override
43+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
44+
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
45+
}
46+
47+
}

‎spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public void onStartup(ServletContext container) throws ServletException {
2121
// ctx.register(JadeTemplateConfiguration.class);
2222
// ctx.register(PushConfiguration.class);
2323
// ctx.setServletContext(container);
24+
25+
//ctx.register(TilesApplicationConfiguration.class);
2426

2527
// Manage the lifecycle of the root application context
2628
container.addListener(new ContextLoaderListener(ctx));

spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationController.java renamed to spring-mvc-simple/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
package com.baeldung.tiles.springmvc;
2-
3-
import org.springframework.stereotype.Controller;
4-
import org.springframework.ui.ModelMap;
5-
import org.springframework.web.bind.annotation.RequestMapping;
6-
import org.springframework.web.bind.annotation.RequestMethod;
7-
8-
@Controller
9-
@RequestMapping("/")
10-
public class ApplicationController {
11-
12-
@RequestMapping(value = { "/" }, method = RequestMethod.GET)
13-
public String homePage(ModelMap model) {
14-
return "home";
15-
}
16-
17-
@RequestMapping(value = { "/apachetiles" }, method = RequestMethod.GET)
18-
public String productsPage(ModelMap model) {
19-
return "apachetiles";
20-
}
21-
22-
@RequestMapping(value = { "/springmvc" }, method = RequestMethod.GET)
23-
public String contactUsPage(ModelMap model) {
24-
return "springmvc";
25-
}
26-
}
1+
package com.baeldung.spring.controller.tiles;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.ui.ModelMap;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
8+
@Controller
9+
@RequestMapping("/")
10+
public class TilesController {
11+
12+
@RequestMapping(value = { "/" }, method = RequestMethod.GET)
13+
public String homePage(ModelMap model) {
14+
return "home";
15+
}
16+
17+
@RequestMapping(value = { "/apachetiles" }, method = RequestMethod.GET)
18+
public String productsPage(ModelMap model) {
19+
return "apachetiles";
20+
}
21+
22+
@RequestMapping(value = { "/springmvc" }, method = RequestMethod.GET)
23+
public String contactUsPage(ModelMap model) {
24+
return "springmvc";
25+
}
26+
}

spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp renamed to spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2-
pageEncoding="ISO-8859-1"%>
3-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4-
<html>
5-
<head>
6-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7-
<title>Apache Tiles</title>
8-
</head>
9-
<body>
10-
<h2>Tiles with Spring MVC Demo</h2>
11-
</body>
1+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2+
pageEncoding="ISO-8859-1"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7+
<title>Apache Tiles</title>
8+
</head>
9+
<body>
10+
<h2>Tiles with Spring MVC Demo</h2>
11+
</body>
1212
</html>

spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/home.jsp renamed to spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/home.jsp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2-
pageEncoding="ISO-8859-1"%>
3-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4-
<html>
5-
<head>
6-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7-
<title>Home</title>
8-
</head>
9-
<body>
10-
<h2>Welcome to Apache Tiles integration with Spring MVC</h2>
11-
</body>
1+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2+
pageEncoding="ISO-8859-1"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7+
<title>Home</title>
8+
</head>
9+
<body>
10+
<h2>Welcome to Apache Tiles integration with Spring MVC</h2>
11+
</body>
1212
</html>

spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/springmvc.jsp renamed to spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/springmvc.jsp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2-
pageEncoding="ISO-8859-1"%>
3-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4-
<html>
5-
<head>
6-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7-
<title>Spring MVC</title>
8-
</head>
9-
<body>
10-
<h2>Spring MVC configured to work with Apache Tiles</h2>
11-
</body>
1+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2+
pageEncoding="ISO-8859-1"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7+
<title>Spring MVC</title>
8+
</head>
9+
<body>
10+
<h2>Spring MVC configured to work with Apache Tiles</h2>
11+
</body>
1212
</html>

spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp renamed to spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2-
pageEncoding="ISO-8859-1"%>
3-
<%@ page isELIgnored="false"%>
4-
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
5-
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
6-
7-
<html>
8-
9-
<head>
10-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
11-
<title><tiles:getAsString name="title" /></title>
12-
<link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
13-
</head>
14-
15-
<body>
16-
<div class="flex-container">
17-
<tiles:insertAttribute name="header" />
18-
<tiles:insertAttribute name="menu" />
19-
<article class="article">
20-
<tiles:insertAttribute name="body" />
21-
</article>
22-
<tiles:insertAttribute name="footer" />
23-
</div>
24-
</body>
25-
</html>
1+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2+
pageEncoding="ISO-8859-1"%>
3+
<%@ page isELIgnored="false"%>
4+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
5+
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
6+
7+
<html>
8+
9+
<head>
10+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
11+
<title><tiles:getAsString name="title" /></title>
12+
<link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
13+
</head>
14+
15+
<body>
16+
<div class="flex-container">
17+
<tiles:insertAttribute name="header" />
18+
<tiles:insertAttribute name="menu" />
19+
<article class="article">
20+
<tiles:insertAttribute name="body" />
21+
</article>
22+
<tiles:insertAttribute name="footer" />
23+
</div>
24+
</body>
25+
</html>

0 commit comments

Comments
 (0)