Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@
<module>spring-mvc-forms-jsp</module>
<module>spring-mvc-forms-thymeleaf</module>
<module>spring-mvc-java</module>
<module>spring-mvc-tiles</module>
<module>spring-mvc-velocity</module>
<module>spring-mvc-webflow</module>
<module>spring-mvc-xml</module>
Expand Down
1 change: 1 addition & 0 deletions spring-mvc-simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
- [Template Engines for Spring](http://www.baeldung.com/spring-template-engines)
- [Spring 5 and Servlet 4 – The PushBuilder](http://www.baeldung.com/spring-5-push)
- [Servlet Redirect vs Forward](http://www.baeldung.com/servlet-redirect-forward)
- [Apache Tiles Integration with Spring MVC](http://www.baeldung.com/spring-mvc-apache-tiles)
7 changes: 7 additions & 0 deletions spring-mvc-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
<artifactId>spring-jade4j</artifactId>
<version>${jade.version}</version>
</dependency>

<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${apache-tiles.version}</version>
</dependency>

<!--Testing -->
<dependency>
Expand Down Expand Up @@ -181,6 +187,7 @@
<scribejava.version>5.1.0</scribejava.version>
<json.version>20180130</json.version>
<spring-oxm.version>5.0.2.RELEASE</spring-oxm.version>
<apache-tiles.version>3.0.8</apache-tiles.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
package com.baeldung.tiles.springmvc;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.baeldung.tiles.springmvc")
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
/**
* Configure TilesConfigurer.
*/
@Bean
public TilesConfigurer tilesConfigurer() {
TilesConfigurer tilesConfigurer = new TilesConfigurer();
tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/views/**/tiles.xml" });
tilesConfigurer.setCheckRefresh(true);
return tilesConfigurer;
}
/**
* Configure ViewResolvers to deliver views.
*/
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
TilesViewResolver viewResolver = new TilesViewResolver();
registry.viewResolver(viewResolver);
}
/**
* Configure ResourceHandlers to serve static resources
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
}
package com.baeldung.spring.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.baeldung.spring.controller.tiles")
public class TilesApplicationConfiguration implements WebMvcConfigurer {

/**
* Configure TilesConfigurer.
*/
@Bean
public TilesConfigurer tilesConfigurer() {
TilesConfigurer tilesConfigurer = new TilesConfigurer();
tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/views/**/tiles.xml" });
tilesConfigurer.setCheckRefresh(true);
return tilesConfigurer;
}

/**
* Configure ViewResolvers to deliver views.
*/
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
TilesViewResolver viewResolver = new TilesViewResolver();
registry.viewResolver(viewResolver);
}

/**
* Configure ResourceHandlers to serve static resources
*/

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public void onStartup(ServletContext container) throws ServletException {
// ctx.register(JadeTemplateConfiguration.class);
// ctx.register(PushConfiguration.class);
// ctx.setServletContext(container);

//ctx.register(TilesApplicationConfiguration.class);

// Manage the lifecycle of the root application context
container.addListener(new ContextLoaderListener(ctx));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package com.baeldung.tiles.springmvc;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/")
public class ApplicationController {
@RequestMapping(value = { "/" }, method = RequestMethod.GET)
public String homePage(ModelMap model) {
return "home";
}
@RequestMapping(value = { "/apachetiles" }, method = RequestMethod.GET)
public String productsPage(ModelMap model) {
return "apachetiles";
}
@RequestMapping(value = { "/springmvc" }, method = RequestMethod.GET)
public String contactUsPage(ModelMap model) {
return "springmvc";
}
}
package com.baeldung.spring.controller.tiles;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
public class TilesController {

@RequestMapping(value = { "/" }, method = RequestMethod.GET)
public String homePage(ModelMap model) {
return "home";
}

@RequestMapping(value = { "/apachetiles" }, method = RequestMethod.GET)
public String productsPage(ModelMap model) {
return "apachetiles";
}

@RequestMapping(value = { "/springmvc" }, method = RequestMethod.GET)
public String contactUsPage(ModelMap model) {
return "springmvc";
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Apache Tiles</title>
</head>
<body>
<h2>Tiles with Spring MVC Demo</h2>
</body>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Apache Tiles</title>
</head>
<body>
<h2>Tiles with Spring MVC Demo</h2>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<body>
<h2>Welcome to Apache Tiles integration with Spring MVC</h2>
</body>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<body>
<h2>Welcome to Apache Tiles integration with Spring MVC</h2>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring MVC</title>
</head>
<body>
<h2>Spring MVC configured to work with Apache Tiles</h2>
</body>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring MVC</title>
</head>
<body>
<h2>Spring MVC configured to work with Apache Tiles</h2>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><tiles:getAsString name="title" /></title>
<link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
</head>
<body>
<div class="flex-container">
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="menu" />
<article class="article">
<tiles:insertAttribute name="body" />
</article>
<tiles:insertAttribute name="footer" />
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><tiles:getAsString name="title" /></title>
<link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
</head>

<body>
<div class="flex-container">
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="menu" />
<article class="article">
<tiles:insertAttribute name="body" />
</article>
<tiles:insertAttribute name="footer" />
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<footer>copyright � Baeldung</footer>

<footer>copyright � Baeldung</footer>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<header>
<h1>Welcome to Spring MVC integration with Apache Tiles</h1>
<header>
<h1>Welcome to Spring MVC integration with Apache Tiles</h1>
</header>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<nav class="nav">
<a href="${pageContext.request.contextPath}/"></a>
<ul id="menu">
<li><a href="${pageContext.request.contextPath}/">Home</a></li>
<li><a href="${pageContext.request.contextPath}/springmvc">SpringMVC</a></li>
<li><a href="${pageContext.request.contextPath}/apachetiles">ApacheTiles</a></li>
</ul>
</nav>
<nav class="nav">
<a href="${pageContext.request.contextPath}/"></a>
<ul id="menu">
<li><a href="${pageContext.request.contextPath}/">Home</a></li>
<li><a href="${pageContext.request.contextPath}/springmvc">SpringMVC</a></li>
<li><a href="${pageContext.request.contextPath}/apachetiles">ApacheTiles</a></li>
</ul>
</nav>
Loading