{"id":189,"date":"2016-02-08T21:28:51","date_gmt":"2016-02-08T21:28:51","guid":{"rendered":"http:\/\/kaizen-koka.com\/?p=189"},"modified":"2018-03-21T13:48:18","modified_gmt":"2018-03-21T13:48:18","slug":"spring-tiles","status":"publish","type":"post","link":"https:\/\/kaizen-koka.com\/?p=189","title":{"rendered":"Spring Tiles"},"content":{"rendered":"<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">Working sample:&nbsp;<a href=\"https:\/\/github.com\/teachkoka\/spring-tiles\">https:\/\/github.com\/teachkoka\/spring-tiles<\/a><\/span><\/span>\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">mvc-dispatcher-servlet.xml<\/span><\/span>\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;bean id=&quot;viewResolver&quot;\r\n      class=&quot;org.springframework.web.servlet.view.UrlBasedViewResolver&quot;&gt;\r\n    &lt;property name=&quot;order&quot; value=&quot;0&quot;\/&gt;\r\n    &lt;property name=&quot;viewClass&quot;&gt;\r\n        &lt;value&gt;\r\n            org.springframework.web.servlet.view.tiles3.TilesView\r\n        &lt;\/value&gt;\r\n    &lt;\/property&gt;\r\n&lt;\/bean&gt;\r\n\r\n&lt;bean id=&quot;tilesConfigurer&quot;\r\n      class=&quot;org.springframework.web.servlet.view.tiles3.TilesConfigurer&quot;&gt;\r\n    &lt;property name=&quot;definitions&quot;&gt;\r\n        &lt;list&gt;\r\n            &lt;value&gt;\/WEB-INF\/tiles.xml&lt;\/value&gt;\r\n        &lt;\/list&gt;\r\n    &lt;\/property&gt;\r\n&lt;\/bean&gt;<\/pre>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">tiles.xml<\/span><\/span>\n<\/p>\n<pre class=\"brush:php;\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;\r\n&lt;!DOCTYPE tiles-definitions PUBLIC\r\n        &quot;-\/\/Apache Software Foundation\/\/DTD Tiles Configuration 3.0\/\/EN&quot;\r\n        &quot;http:\/\/tiles.apache.org\/dtds\/tiles-config_3_0.dtd&quot;&gt;\r\n\r\n&lt;tiles-definitions&gt;\r\n     &lt;definition name=&quot;base.defination&quot; template=&quot;\/WEB-INF\/pages\/layout.jsp&quot;&gt;\r\n         &lt;put-attribute name=&quot;title&quot; value=&quot;&quot;\/&gt;\r\n         &lt;put-attribute name=&quot;header&quot; value=&quot;\/WEB-INF\/pages\/header.jsp&quot;\/&gt;\r\n         &lt;put-attribute name=&quot;menu&quot; value=&quot;\/WEB-INF\/pages\/menu.jsp&quot;\/&gt;\r\n         &lt;put-attribute name=&quot;body&quot; value=&quot;&quot;\/&gt;\r\n         &lt;put-attribute name=&quot;footer&quot; value=&quot;\/WEB-INF\/pages\/footer.jsp&quot; \/&gt;\r\n     &lt;\/definition&gt;\r\n\r\n     &lt;definition name=&quot;student-login&quot; extends=&quot;base.defination&quot;&gt;\r\n         &lt;put-attribute name=&quot;title&quot; value=&quot;student login&quot;\/&gt;\r\n         &lt;put-attribute name=&quot;body&quot; value=&quot;\/WEB-INF\/pages\/student-login.jsp&quot;\/&gt;\r\n     &lt;\/definition&gt;\r\n\r\n    &lt;definition name=&quot;result\/success&quot; extends=&quot;base.defination&quot;&gt;\r\n        &lt;put-attribute name=&quot;title&quot; value=&quot;success page&quot;\/&gt;\r\n        &lt;put-attribute name=&quot;body&quot; value=&quot;\/WEB-INF\/pages\/result\/success.jsp&quot;\/&gt;\r\n    &lt;\/definition&gt;\r\n\r\n&lt;\/tiles-definitions&gt;<\/pre>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\tAppConfig\n<\/p>\n<pre class=\"brush:java;\">\r\npackage com.b8.spring.javaconfig.config;\r\n\r\nimport javax.sql.DataSource;\r\n\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.ComponentScan;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.context.support.ResourceBundleMessageSource;\r\nimport org.springframework.jdbc.core.JdbcTemplate;\r\nimport org.springframework.jdbc.datasource.DriverManagerDataSource;\r\nimport org.springframework.web.servlet.ViewResolver;\r\nimport org.springframework.web.servlet.config.annotation.EnableWebMvc;\r\nimport org.springframework.web.servlet.view.InternalResourceViewResolver;\r\nimport org.springframework.web.servlet.view.UrlBasedViewResolver;\r\nimport org.springframework.web.servlet.view.tiles3.TilesConfigurer;\r\n\r\n@Configuration\r\n@ComponentScan(basePackages={&quot;com.b8.spring.javaconfig&quot;})\r\n@EnableWebMvc\r\npublic class AppConfig {\r\n\t\r\n\t@Bean\r\n\tpublic DataSource dataSource(){\r\n\t\tDriverManagerDataSource dataSource = new DriverManagerDataSource();\r\n\t\tdataSource.setDriverClassName(&quot;org.postgresql.Driver&quot;);\r\n\t\tdataSource.setUrl(&quot;jdbc:postgresql:\/\/127.0.0.1:5432\/postgres&quot;);\r\n\t\tdataSource.setUsername(&quot;postgres&quot;);\r\n\t\tdataSource.setPassword(&quot;abcd12345&quot;);\r\n\t\treturn dataSource;\r\n\t}\r\n\t\r\n\t@Bean\r\n\tpublic JdbcTemplate jdbcTemplate(){\r\n\t\tJdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource());\r\n\t\treturn jdbcTemplate;\r\n\t}\r\n\t\r\n\t@Bean\r\n\tpublic TilesConfigurer getTilesConfigurer() {\r\n\t\tTilesConfigurer tilesConfigurer = new TilesConfigurer();\r\n\r\n\t\ttilesConfigurer.setDefinitions(new String[] { &quot;\/WEB-INF\/tiles.xml&quot; });\r\n\t\ttilesConfigurer.setCheckRefresh(true);\r\n\t\treturn tilesConfigurer;\r\n\t}\r\n\r\n\t@Bean\r\n\tpublic UrlBasedViewResolver viewResolver(){\r\n\t\tUrlBasedViewResolver ubvr = new UrlBasedViewResolver();\r\n\t\tubvr.setOrder(0);\r\n\t\tubvr.setViewClass(org.springframework.web.servlet.view.tiles3.TilesView.class);\r\n\t\treturn ubvr;\r\n\t}\r\n\t\r\n\/*\t@Bean\r\n\tpublic InternalResourceViewResolver viewResolver(){\r\n\t\tInternalResourceViewResolver irvr = new InternalResourceViewResolver();\r\n\t\tirvr.setPrefix(&quot;\/WEB-INF\/pages\/&quot;);\r\n\t\tirvr.setSuffix(&quot;.jsp&quot;);\r\n\t\treturn irvr;\r\n\t}*\/\r\n\t\r\n\t@Bean\r\n\tpublic ResourceBundleMessageSource messageSource(){\r\n\t\tResourceBundleMessageSource rbms = new ResourceBundleMessageSource();\r\n\t\trbms.setBasename(&quot;messages&quot;);\r\n\t\treturn rbms;\r\n\t}\r\n\r\n\t\r\n}\r\n<\/pre>\n<p>\n\tAppInitializer.java\n<\/p>\n<pre class=\"brush:java;\">\r\npackage com.b8.spring.javaconfig.config;\r\n\r\nimport javax.servlet.ServletContext;\r\nimport javax.servlet.ServletException;\r\nimport javax.servlet.ServletRegistration.Dynamic;\r\n\r\nimport org.springframework.web.WebApplicationInitializer;\r\nimport org.springframework.web.context.ContextLoaderListener;\r\nimport org.springframework.web.context.support.AnnotationConfigWebApplicationContext;\r\nimport org.springframework.web.servlet.DispatcherServlet;\r\n\r\npublic class AppInitializeer implements WebApplicationInitializer{\r\n\r\n\tpublic void onStartup(ServletContext servletContext)\r\n\t\t\tthrows ServletException {\r\n\t\t\r\n\t\tAnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();\r\n\t\tcontext.register(AppConfig.class);\r\n\t\t\r\n\t\tservletContext.addListener(new ContextLoaderListener(context));\r\n\t\t\r\n\t\tDynamic servlet = servletContext.addServlet(&quot;dispatcher&quot;, new DispatcherServlet(context));\r\n\t\tservlet.addMapping(&quot;\/&quot;);\r\n\t\tservlet.setLoadOnStartup(1);\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif;\"><span style=\"font-size:14px;\">Layout.jsp<\/span><\/span>\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;table border=&quot;1&quot; cellpadding=&quot;2&quot; cellspacing=&quot;2&quot; align=&quot;center&quot;&gt;\r\n  &lt;tr&gt;\r\n    &lt;td height=&quot;30&quot; colspan=&quot;2&quot;&gt;\r\n      &lt;tiles:insertAttribute name=&quot;header&quot;\/&gt;\r\n    &lt;\/td&gt;\r\n  &lt;\/tr&gt;\r\n  &lt;tr&gt;\r\n     &lt;td height=&quot;250&quot;&gt;&lt;tiles:insertAttribute name=&quot;menu&quot;\/&gt;&lt;\/td&gt;\r\n     &lt;td width=&quot;350&quot;&gt;&lt;tiles:insertAttribute name=&quot;body&quot;\/&gt; &lt;\/td&gt;\r\n  &lt;\/tr&gt;\r\n  &lt;tr&gt;\r\n\r\n  &lt;\/tr&gt;&lt;td height=&quot;30&quot; colspan=&quot;2&quot;&gt;\r\n    &lt;tiles:insertAttribute name=&quot;footer&quot;\/&gt;\r\n&lt;\/td&gt;\r\n\r\n&lt;\/table&gt;<\/pre>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\tBootStrap\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;%@ page language=&quot;java&quot; contentType=&quot;text\/html; charset=ISO-8859-1&quot;\r\n         pageEncoding=&quot;ISO-8859-1&quot;%&gt;\r\n&lt;!DOCTYPE html PUBLIC &quot;-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN&quot; &quot;http:\/\/www.w3.org\/TR\/html4\/loose.dtd&quot;&gt;\r\n&lt;%@ taglib uri=&quot;http:\/\/tiles.apache.org\/tags-tiles&quot; prefix=&quot;tiles&quot;%&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=ISO-8859-1&quot;&gt;\r\n    &lt;title&gt;Insert title here&lt;\/title&gt;\r\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;\r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;http:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.6\/css\/bootstrap.min.css&quot;&gt;\r\n    &lt;script src=&quot;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.12.0\/jquery.min.js&quot;&gt;&lt;\/script&gt;\r\n    &lt;script src=&quot;http:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.6\/js\/bootstrap.min.js&quot;&gt;&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;div class=&quot;container&quot;&gt;\r\n    &lt;div class=&quot;table-responsive&quot;&gt;\r\n        &lt;table class=&quot;table&quot; &gt;\r\n            &lt;tr&gt;\r\n                &lt;td height=&quot;100&quot; colspan=&quot;2&quot;  style=&quot;background-color: Azure; border: thick;font: bold;&quot;&gt;\r\n                    &lt;tiles:insertAttribute name=&quot;header&quot;\/&gt;\r\n                &lt;\/td&gt;\r\n            &lt;\/tr&gt;\r\n            &lt;tr&gt;\r\n                &lt;td height=&quot;250&quot;  width=&quot;200&quot; style=&quot;background-color:BurlyWood; border: thick;font: bold;&quot;&gt;\r\n                    &lt;tiles:insertAttribute name=&quot;menu&quot;\/&gt;\r\n                &lt;\/td&gt;\r\n                &lt;td height=&quot;350&quot; width=&quot;400&quot; style=&quot;background-color: lightblue; border: thick;font: bold;&quot;&gt;\r\n                  &lt;%--  &lt;tiles:insertAttribute name=&quot;title&quot; \/&gt;&lt;br&gt;--%&gt;\r\n                    &lt;tiles:insertAttribute name=&quot;body&quot;\/&gt;\r\n                &lt;\/td&gt;\r\n            &lt;\/tr&gt;\r\n            &lt;tr&gt;\r\n                &lt;td height=&quot;100&quot;  colspan=&quot;2&quot; style=&quot;background-color: Azure; border: thick;font: bold;&quot;&gt;\r\n                    &lt;tiles:insertAttribute name=&quot;footer&quot;\/&gt;\r\n                &lt;\/td&gt;\r\n            &lt;\/tr&gt;\r\n        &lt;\/table&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working sample:&nbsp;https:\/\/github.com\/teachkoka\/spring-tiles &nbsp; mvc-dispatcher-servlet.xml &lt;bean id=&quot;viewResolver&quot; class=&quot;org.springframework.web.servlet.view.UrlBasedViewResolver&quot;&gt; &lt;property name=&quot;order&quot; value=&quot;0&quot;\/&gt; &lt;property name=&quot;viewClass&quot;&gt; &lt;value&gt; org.springframework.web.servlet.view.tiles3.TilesView &lt;\/value&gt; &lt;\/property&gt; &lt;\/bean&gt; &lt;bean id=&quot;tilesConfigurer&quot; class=&quot;org.springframework.web.servlet.view.tiles3.TilesConfigurer&quot;&gt; &lt;property name=&quot;definitions&quot;&gt; &lt;list&gt; &lt;value&gt;\/WEB-INF\/tiles.xml&lt;\/value&gt; &lt;\/list&gt; &lt;\/property&gt; &lt;\/bean&gt; tiles.xml &lt;?xml version=&quot;1.0&quot; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[16],"tags":[],"class_list":["post-189","post","type-post","status-publish","format-standard","hentry","category-spring-technologies"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p70lnf-33","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=189"}],"version-history":[{"count":4,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":502,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions\/502"}],"wp:attachment":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}