From 6d4b45e1aa6acd81f9dcfba6091d2bc95ac98145 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 21 Jun 2020 22:10:19 +0530 Subject: [PATCH] moved apache tiles related code in spring-mvc-views module --- spring-mvc-basics-2/README.md | 1 - spring-mvc-basics-2/pom.xml | 7 ---- .../spring/configuration/WebInitializer.java | 2 -- spring-mvc-views/README.md | 1 + spring-mvc-views/pom.xml | 7 ++++ .../TilesApplicationConfiguration.java | 4 +-- .../themes/config/WebInitializer.java | 1 + .../themes/controllers}/TilesController.java | 2 +- .../WEB-INF/views/pages/apachetiles.jsp | 0 .../main/webapp/WEB-INF/views/pages/home.jsp | 12 +++++++ .../webapp/WEB-INF/views/pages/springmvc.jsp | 12 +++++++ .../views/tiles/layouts/defaultLayout.jsp | 0 .../views/tiles/templates/defaultFooter.jsp | 0 .../views/tiles/templates/defaultHeader.jsp | 0 .../views/tiles/templates/defaultMenu.jsp | 0 .../main/webapp/WEB-INF/views/tiles/tiles.xml | 0 .../src/main/webapp/static/css/app.css | 36 +++++++++++++++++++ 17 files changed, 72 insertions(+), 13 deletions(-) rename {spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration => spring-mvc-views/src/main/java/com/baeldung/themes/config}/TilesApplicationConfiguration.java (93%) rename {spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles => spring-mvc-views/src/main/java/com/baeldung/themes/controllers}/TilesController.java (94%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp (100%) create mode 100644 spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp create mode 100644 spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp (100%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp (100%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp (100%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp (100%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/tiles.xml (100%) create mode 100644 spring-mvc-views/src/main/webapp/static/css/app.css diff --git a/spring-mvc-basics-2/README.md b/spring-mvc-basics-2/README.md index 5c1c671f73..cbc9f93e93 100644 --- a/spring-mvc-basics-2/README.md +++ b/spring-mvc-basics-2/README.md @@ -7,7 +7,6 @@ This module contains articles about Spring MVC - [Template Engines for Spring](https://www.baeldung.com/spring-template-engines) - [Spring 5 and Servlet 4 – The PushBuilder](https://www.baeldung.com/spring-5-push) - [Servlet Redirect vs Forward](https://www.baeldung.com/servlet-redirect-forward) -- [Apache Tiles Integration with Spring MVC](https://www.baeldung.com/spring-mvc-apache-tiles) - [Guide to Spring Email](https://www.baeldung.com/spring-email) - [Using ThymeLeaf and FreeMarker Emails Templates with Spring](https://www.baeldung.com/spring-email-templates) - [Request Method Not Supported (405) in Spring](https://www.baeldung.com/spring-request-method-not-supported-405) diff --git a/spring-mvc-basics-2/pom.xml b/spring-mvc-basics-2/pom.xml index 4c3041a209..026ddf8e72 100644 --- a/spring-mvc-basics-2/pom.xml +++ b/spring-mvc-basics-2/pom.xml @@ -99,12 +99,6 @@ ${jade.version} - - org.apache.tiles - tiles-jsp - ${apache-tiles.version} - - org.springframework @@ -178,7 +172,6 @@ 1.4.9 5.1.0 20180130 - 3.0.8 1.6.1 diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java index 4d43549440..aaa2443105 100644 --- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java +++ b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java @@ -23,8 +23,6 @@ public class WebInitializer implements WebApplicationInitializer { ctx.register(EmailConfiguration.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-views/README.md b/spring-mvc-views/README.md index 7aa05699f3..0323349130 100644 --- a/spring-mvc-views/README.md +++ b/spring-mvc-views/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Spring MVC Themes](https://www.baeldung.com/spring-mvc-themes) +- [Apache Tiles Integration with Spring MVC](https://www.baeldung.com/spring-mvc-apache-tiles) diff --git a/spring-mvc-views/pom.xml b/spring-mvc-views/pom.xml index b23403fe31..452805bd53 100644 --- a/spring-mvc-views/pom.xml +++ b/spring-mvc-views/pom.xml @@ -74,6 +74,12 @@ spring-security-taglibs ${spring.security.version} + + + org.apache.tiles + tiles-jsp + ${apache-tiles.version} + @@ -115,6 +121,7 @@ 2.5.0 5.4.9.Final enter-location-of-server + 3.0.8 \ No newline at end of file diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java b/spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java similarity index 93% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java rename to spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java index de2b7fe68f..886c8987e8 100644 --- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java +++ b/spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.configuration; +package com.baeldung.themes.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -12,7 +12,7 @@ import org.springframework.web.servlet.view.tiles3.TilesViewResolver; @Configuration @EnableWebMvc -@ComponentScan(basePackages = "com.baeldung.spring.controller.tiles") +@ComponentScan(basePackages = "com.baeldung.themes") public class TilesApplicationConfiguration implements WebMvcConfigurer { /** diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java b/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java index 3fbe8d043d..3333d664d7 100644 --- a/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java +++ b/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java @@ -14,6 +14,7 @@ public class WebInitializer implements WebApplicationInitializer { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(DataSourceConfig.class); context.register(ThemeMVCConfig.class); + //context.register(TilesApplicationConfiguration.class); servletContext.addListener(new ContextLoaderListener(context)); diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java b/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java similarity index 94% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java rename to spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java index 319340b886..11a3d3d197 100644 --- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java +++ b/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.controller.tiles; +package com.baeldung.themes.controllers; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp new file mode 100644 index 0000000000..47157a5d2a --- /dev/null +++ b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp @@ -0,0 +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

+ + \ No newline at end of file diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp new file mode 100644 index 0000000000..497e04901a --- /dev/null +++ b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp @@ -0,0 +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

+ + \ No newline at end of file diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/tiles.xml b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/tiles.xml rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml diff --git a/spring-mvc-views/src/main/webapp/static/css/app.css b/spring-mvc-views/src/main/webapp/static/css/app.css new file mode 100644 index 0000000000..9976e5406e --- /dev/null +++ b/spring-mvc-views/src/main/webapp/static/css/app.css @@ -0,0 +1,36 @@ +.flex-container { + display: -webkit-flex; + display: flex; + -webkit-flex-flow: row wrap; + flex-flow: row wrap; + text-align: center; +} + +.flex-container > * { + padding: 15px; + -webkit-flex: 1 100%; + flex: 1 100%; +} + +.article { + text-align: left; +} + +header {background: black;color:white;} +footer {background: #aaa;color:white;} +.nav {background:#eee;} + +.nav ul { + list-style-type: none; + padding: 0; +} + +.nav ul a { + text-decoration: none; +} + +@media all and (min-width: 768px) { + .nav {text-align:left;-webkit-flex: 1 auto;flex:1 auto;-webkit-order:1;order:1;} + .article {-webkit-flex:5 0px;flex:5 0px;-webkit-order:2;order:2;} + footer {-webkit-order:3;order:3;} +} \ No newline at end of file