diff --git a/pom.xml b/pom.xml index f823acfa6a..8c87983870 100644 --- a/pom.xml +++ b/pom.xml @@ -183,7 +183,6 @@ spring-mvc-forms-jsp spring-mvc-forms-thymeleaf spring-mvc-java - spring-mvc-tiles spring-mvc-velocity spring-mvc-webflow spring-mvc-xml diff --git a/spring-mvc-simple/README.md b/spring-mvc-simple/README.md index 600a448076..3505fb8009 100644 --- a/spring-mvc-simple/README.md +++ b/spring-mvc-simple/README.md @@ -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) diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index 1464958865..08eab59540 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -88,6 +88,12 @@ spring-jade4j ${jade.version} + + + org.apache.tiles + tiles-jsp + ${apache-tiles.version} + @@ -181,6 +187,7 @@ 5.1.0 20180130 5.0.2.RELEASE + 3.0.8 diff --git a/spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationConfiguration.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java similarity index 86% rename from spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationConfiguration.java rename to spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java index d2e90a4f53..de2b7fe68f 100644 --- a/spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationConfiguration.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java @@ -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/"); + } + +} diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java index 09030a8347..74094a11c7 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java @@ -21,6 +21,8 @@ public class WebInitializer implements WebApplicationInitializer { // 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)); diff --git a/spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationController.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java similarity index 87% rename from spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationController.java rename to spring-mvc-simple/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java index 1a348d1c26..319340b886 100644 --- a/spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationController.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java @@ -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"; + } +} diff --git a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp b/spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp similarity index 97% rename from spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp rename to spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp index 9936957c04..918c52ab45 100644 --- a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp @@ -1,12 +1,12 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> - - - - -Apache Tiles - - -

Tiles with Spring MVC Demo

- +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Apache Tiles + + +

Tiles with Spring MVC Demo

+ \ No newline at end of file diff --git a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/home.jsp b/spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/home.jsp similarity index 97% rename from spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/home.jsp rename to spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/home.jsp index b501d4968e..47157a5d2a 100644 --- a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/home.jsp +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/home.jsp @@ -1,12 +1,12 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> - - - - -Home - - -

Welcome to Apache Tiles integration with Spring MVC

- +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Home + + +

Welcome to Apache Tiles integration with Spring MVC

+ \ No newline at end of file diff --git a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/springmvc.jsp b/spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/springmvc.jsp similarity index 97% rename from spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/springmvc.jsp rename to spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/springmvc.jsp index 209b1004de..497e04901a 100644 --- a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/pages/springmvc.jsp +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/pages/springmvc.jsp @@ -1,12 +1,12 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> - - - - -Spring MVC - - -

Spring MVC configured to work with Apache Tiles

- +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Spring MVC + + +

Spring MVC configured to work with Apache Tiles

+ \ No newline at end of file diff --git a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp similarity index 96% rename from spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp rename to spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp index 2370ad4ab1..064f3ee78b 100644 --- a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp @@ -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"%> - - - - - -<tiles:getAsString name="title" /> - - - - -
- - -
- -
- -
- - +<%@ 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"%> + + + + + +<tiles:getAsString name="title" /> + + + + +
+ + +
+ +
+ +
+ + diff --git a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp similarity index 95% rename from spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp rename to spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp index 3849cc5230..0946549e06 100644 --- a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp @@ -1,2 +1,2 @@ - - + + diff --git a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp similarity index 97% rename from spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp rename to spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp index 8a878c857d..4ad29d82e0 100644 --- a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp @@ -1,3 +1,3 @@ -
-

Welcome to Spring MVC integration with Apache Tiles

+
+

Welcome to Spring MVC integration with Apache Tiles

\ No newline at end of file diff --git a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp similarity index 97% rename from spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp rename to spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp index 2c91eace85..17502fd051 100644 --- a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp @@ -1,8 +1,8 @@ - + diff --git a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/tiles.xml b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/tiles.xml similarity index 97% rename from spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/tiles.xml rename to spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/tiles.xml index 789fbd809a..648ecb44fe 100644 --- a/spring-mvc-tiles/src/main/webapp/WEB-INF/views/tiles/tiles.xml +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/tiles/tiles.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-mvc-tiles/src/main/webapp/static/css/app.css b/spring-mvc-simple/src/main/webapp/static/css/app.css similarity index 100% rename from spring-mvc-tiles/src/main/webapp/static/css/app.css rename to spring-mvc-simple/src/main/webapp/static/css/app.css diff --git a/spring-mvc-tiles/README.md b/spring-mvc-tiles/README.md deleted file mode 100644 index 58991005f5..0000000000 --- a/spring-mvc-tiles/README.md +++ /dev/null @@ -1,2 +0,0 @@ -###Relevant Articles: -- [Apache Tiles Integration with Spring MVC](http://www.baeldung.com/spring-mvc-apache-tiles) diff --git a/spring-mvc-tiles/pom.xml b/spring-mvc-tiles/pom.xml deleted file mode 100644 index 007f7c0844..0000000000 --- a/spring-mvc-tiles/pom.xml +++ /dev/null @@ -1,93 +0,0 @@ - - 4.0.0 - com.baeldung - spring-mvc-tiles - 0.0.1-SNAPSHOT - war - spring-mvc-tiles - Integrating Spring MVC with Apache Tiles - - - com.baeldung - parent-spring-4 - 0.0.1-SNAPSHOT - ../parent-spring-4 - - - - - - org.springframework - spring-core - ${spring.version} - - - commons-logging - commons-logging - - - - - org.springframework - spring-web - ${spring.version} - - - org.springframework - spring-webmvc - ${spring.version} - - - - org.apache.tiles - tiles-jsp - ${apache-tiles.version} - - - - - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} - - - javax.servlet.jsp - javax.servlet.jsp-api - ${javax.servlet.jsp-api.version} - - - javax.servlet - jstl - ${jstl.version} - - - - - - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - src/main/webapp - spring-mvc-tiles - false - - - - - spring-mvc-tiles - - - - 3.0.7 - 3.1.0 - 2.3.1 - 1.2 - 2.6 - - - diff --git a/spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationInitializer.java b/spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationInitializer.java deleted file mode 100644 index 79583dbe83..0000000000 --- a/spring-mvc-tiles/src/main/java/com/baeldung/tiles/springmvc/ApplicationInitializer.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.tiles.springmvc; - -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; - -public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - - @Override - protected Class[] getRootConfigClasses() { - return new Class[] { ApplicationConfiguration.class }; - } - - @Override - protected Class[] getServletConfigClasses() { - return null; - } - - @Override - protected String[] getServletMappings() { - return new String[] { "/" }; - } - -}