0

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>
Roman C
  • 49,761
  • 33
  • 66
  • 176
Natta Wang
  • 553
  • 11
  • 18
  • Please include project configuration details. – Dave Newton Sep 02 '20 at 14:05
  • Struts2 no longer support for tiles plugin. To implement old plugin you can use [this](https://stackoverflow.com/a/32358332/573032) answer – Roman C Sep 02 '20 at 18:48
  • @RomanC I think my question CLEARLY specified that I want to use tiles-plugin of Struts2 together with existing tiles-plugin of Struts1 version, because I'm doing migration and it cannot finish in short time because of load of work. And this https://struts.apache.org/plugins/tiles/ is what I'm following. And I read your answer in the link, but all of them don't have anything that show the implementation of both Struts2-tiles-plugin and Struts1-tiles-plugin together for migration purpose. I come here I need help, not closing my question. – Natta Wang Sep 04 '20 at 00:04
  • @DaveNewton I added settings code and what I implemented into project, if any other that you need to know please tell me. – Natta Wang Sep 04 '20 at 00:31

0 Answers0