I'm doing on migrating Struts1 to Struts2 and one of component is TilesPlugin of Struts1 version. I've read the instruction of Struts2 tiles-plugin implementation and follow those steps, but found it is not loaded the configure as I expected. Here's the link https://struts.apache.org/plugins/tiles/
Question is I need to know how to implement new version of tiles-plugin
of Struts2 together with existing TilesPlugin of Struts1. (I can't migrate all actions to use newer tiles-plugin in the same time, it's quite big load of work to do)
pom.xml (I added only struts2-tiles-plugin
but it error on runtime, then add slf4j
to solve it)
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>${struts2.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
tiles.xml
<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/path/to/layout.jsp">
<put-attribute name="title" value="default title layout" />
</definition>
<definition name="page1" extends="baseLayout">
<put-attribute name="title" value="page 1 title" />
<put-attribute name="body" value="/WEB-INF/view/page1.jsp" />
<put-attribute name="js" value="/WEB-INF/view/include/include_js.jsp" />
</definition>
</tiles-definitions>
web.xml (Add to beginning of existing)
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<context-param>
<param-name>tilesDefinitions</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
struts.xml (Add this inside <package>
tag)
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
</result-types>
Add type="tiles"
property into target <result>
struts-config.xml (This is Struts1 config and existing of struts1-tiles-plugin)
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/tiles-def.xml" />
<set-property property="definitions-debug" value="2" />
<set-property property="definitions-parser-details" value="2" />
<set-property property="definitions-parser-validate" value="true" />
</plug-in>
layout.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="EUC-JP" session="true" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=x-euc-jp">
<meta http-equiv="Content-Language" content="ja">
<title><tiles:getAsString name="title"/></title>
<tiles:insertAttribute name="js"/>
</head>
<tiles:insertAttribute name="body"/>
</html>