You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2024/11/14 12:23:01 UTC

(struts-examples) branch feature/multiple-decorators created (now 1efef9c)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch feature/multiple-decorators
in repository https://gitbox.apache.org/repos/asf/struts-examples.git


      at 1efef9c  Extends example with Sitemesh 3 to support multiple decorators

This branch includes the following new commits:

     new 46a3689  Adds simple example with Sitemesh3 integration
     new 1efef9c  Extends example with Sitemesh 3 to support multiple decorators

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(struts-examples) 01/02: Adds simple example with Sitemesh3 integration

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch feature/multiple-decorators
in repository https://gitbox.apache.org/repos/asf/struts-examples.git

commit 46a36898686060ead377e163c3edf31a2ad568a0
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Fri Oct 11 08:12:53 2024 +0200

    Adds simple example with Sitemesh3 integration
---
 pom.xml                                            |  1 +
 sitemesh3/README.md                                |  6 ++
 sitemesh3/pom.xml                                  | 69 ++++++++++++++++++++++
 .../src/main/resources/DefaultMessages.properties  |  5 ++
 .../main/resources/DefaultMessages_es.properties   |  5 ++
 sitemesh3/src/main/resources/log4j2.xml            | 14 +++++
 sitemesh3/src/main/resources/struts.xml            | 22 +++++++
 .../main/webapp/WEB-INF/decorators/decorator.html  |  9 +++
 sitemesh3/src/main/webapp/WEB-INF/hello.jsp        | 30 ++++++++++
 sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml    |  3 +
 sitemesh3/src/main/webapp/WEB-INF/web.xml          | 44 ++++++++++++++
 sitemesh3/src/main/webapp/index.html               | 10 ++++
 12 files changed, 218 insertions(+)

diff --git a/pom.xml b/pom.xml
index 994105d..debfc0c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,6 +122,7 @@
         <module>wildcard-method-selection</module>
         <module>wildcard-regex</module>
         <module>jasperreports</module>
+        <module>sitemesh3</module>
   </modules>
 
     <dependencyManagement>
diff --git a/sitemesh3/README.md b/sitemesh3/README.md
new file mode 100644
index 0000000..ca3308a
--- /dev/null
+++ b/sitemesh3/README.md
@@ -0,0 +1,6 @@
+Struts 2 Sitemesh 3 example
+==================
+
+Simple Struts 2 project which demonstrates Sitemesh 3 usage
+
+Published under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
diff --git a/sitemesh3/pom.xml b/sitemesh3/pom.xml
new file mode 100644
index 0000000..7f31a85
--- /dev/null
+++ b/sitemesh3/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.struts</groupId>
+        <artifactId>struts-examples</artifactId>
+        <version>2.0.0</version>
+    </parent>
+
+    <artifactId>sitemesh3</artifactId>
+    <name>Struts Sitemesh 3 Example</name>
+
+    <packaging>war</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.sitemesh</groupId>
+            <artifactId>sitemesh</artifactId>
+            <version>3.2.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.struts</groupId>
+            <artifactId>struts2-config-browser-plugin</artifactId>
+            <version>${struts2.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <version>${log4j2.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.struts</groupId>
+            <artifactId>struts2-junit-plugin</artifactId>
+            <version>${struts2.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.13.2</version>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.eclipse.jetty</groupId>
+                <artifactId>jetty-maven-plugin</artifactId>
+                <version>${jetty-plugin.version}</version>
+                <configuration>
+                    <webApp>
+                        <contextPath>/${project.artifactId}</contextPath>
+                    </webApp>
+                    <stopKey>CTRL+C</stopKey>
+                    <stopPort>8999</stopPort>
+                    <scan>10</scan>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/sitemesh3/src/main/resources/DefaultMessages.properties b/sitemesh3/src/main/resources/DefaultMessages.properties
new file mode 100644
index 0000000..074cd28
--- /dev/null
+++ b/sitemesh3/src/main/resources/DefaultMessages.properties
@@ -0,0 +1,5 @@
+HelloWorld.message = Struts is up and running...
+requiredstring=  ${getText(fieldName)} is required.
+password = Password
+username = User Name
+Missing.message =  This feature is under construction. Please try again in the next iteration.
diff --git a/sitemesh3/src/main/resources/DefaultMessages_es.properties b/sitemesh3/src/main/resources/DefaultMessages_es.properties
new file mode 100644
index 0000000..ce5d083
--- /dev/null
+++ b/sitemesh3/src/main/resources/DefaultMessages_es.properties
@@ -0,0 +1,5 @@
+HelloWorld.message = \u00A1Struts est\u00E1 bien\!...
+requiredstring = ${getText(fieldName)} es requerido.
+password = Contrase\u00F1a
+username = Nombre de Usuario
+Missing.message = P\u00E1gina bajo construcci\u00F3n, trate de nuevo en la proxima versi\u00F3n.
\ No newline at end of file
diff --git a/sitemesh3/src/main/resources/log4j2.xml b/sitemesh3/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..1f4e3df
--- /dev/null
+++ b/sitemesh3/src/main/resources/log4j2.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration>
+  <Appenders>
+    <Console name="STDOUT" target="SYSTEM_OUT">
+      <PatternLayout pattern="[%-5p] %C{2} (%F:%L) - %m%n"/>
+    </Console>
+  </Appenders>
+  <Loggers>
+    <Root level="info">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+    <Logger name="org.apache.struts2.tiles" level="trace"/>
+  </Loggers>
+</Configuration>
diff --git a/sitemesh3/src/main/resources/struts.xml b/sitemesh3/src/main/resources/struts.xml
new file mode 100644
index 0000000..e95c041
--- /dev/null
+++ b/sitemesh3/src/main/resources/struts.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE struts PUBLIC
+        "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
+        "https://struts.apache.org/dtds/struts-6.0.dtd">
+<struts>
+    <constant name="struts.devMode" value="true"/>
+    <constant name="struts.custom.i18n.resources" value="DefaultMessages"/>
+
+    <package name="default" extends="struts-default">
+        <default-action-ref name="index"/>
+        <action name="index">
+            <result type="redirectAction">
+                <param name="actionName">hello</param>
+            </result>
+        </action>
+
+      <action name="hello">
+        <result>/WEB-INF/hello.jsp</result>
+      </action>
+
+    </package>
+</struts>
diff --git a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html
new file mode 100644
index 0000000..eeb64a1
--- /dev/null
+++ b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html
@@ -0,0 +1,9 @@
+<html>
+<head>
+    <title><sitemesh:write property="title"/></title>
+    <sitemesh:write property="head"/>
+</head>
+<body>
+<sitemesh:write property="body"/>
+</body>
+</html>
\ No newline at end of file
diff --git a/sitemesh3/src/main/webapp/WEB-INF/hello.jsp b/sitemesh3/src/main/webapp/WEB-INF/hello.jsp
new file mode 100644
index 0000000..a4aa404
--- /dev/null
+++ b/sitemesh3/src/main/webapp/WEB-INF/hello.jsp
@@ -0,0 +1,30 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+    <title>SiteMesh example: Hello World</title>
+</head>
+<body>
+<h2><s:text name="%{getText('HelloWorld.message')}"/></h2>
+
+<h3>Languages</h3>
+<ul>
+    <li>
+        <s:url var="url" action="hello">
+            <s:param name="request_locale">en</s:param>
+        </s:url>
+        <s:a href="%{url}">English</s:a>
+        <br/>
+        <code>EL: ${url}</code>
+    </li>
+    <li>
+        <s:url var="url" action="hello">
+            <s:param name="request_locale">es</s:param>
+        </s:url>
+        <s:a href="%{url}">Espanol</s:a>
+        <br/>
+        <code>EL: ${url}</code>
+    </li>
+</ul>
+</body>
+</html>
diff --git a/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml b/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml
new file mode 100644
index 0000000..77fbc3b
--- /dev/null
+++ b/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml
@@ -0,0 +1,3 @@
+<sitemesh>
+    <mapping path="/*" decorator="decorator.html"/>
+</sitemesh>
\ No newline at end of file
diff --git a/sitemesh3/src/main/webapp/WEB-INF/web.xml b/sitemesh3/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ff5bac7
--- /dev/null
+++ b/sitemesh3/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
+         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
+         version="3.1">
+
+    <display-name>Struts Tiles 2 Demo</display-name>
+
+    <filter>
+        <filter-name>struts2-prepare</filter-name>
+        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
+    </filter>
+
+    <filter>
+        <filter-name>sitemesh</filter-name>
+        <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
+    </filter>
+
+    <filter>
+        <filter-name>struts2-execute</filter-name>
+        <filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class>
+    </filter>
+
+    <filter-mapping>
+        <filter-name>struts2-prepare</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+
+    <filter-mapping>
+        <filter-name>sitemesh</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+
+    <filter-mapping>
+        <filter-name>struts2-execute</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+
+    <welcome-file-list>
+        <welcome-file>/index.html</welcome-file>
+    </welcome-file-list>
+
+</web-app>
diff --git a/sitemesh3/src/main/webapp/index.html b/sitemesh3/src/main/webapp/index.html
new file mode 100644
index 0000000..dc2bbd0
--- /dev/null
+++ b/sitemesh3/src/main/webapp/index.html
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=example/HelloWorld.action">
+</head>
+
+<body>
+<p>Loading ...</p>
+</body>
+</html>


(struts-examples) 02/02: Extends example with Sitemesh 3 to support multiple decorators

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch feature/multiple-decorators
in repository https://gitbox.apache.org/repos/asf/struts-examples.git

commit 1efef9c4cd182d3365f8f988a4a8d75aa93cee34
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Thu Nov 14 13:22:52 2024 +0100

    Extends example with Sitemesh 3 to support multiple decorators
---
 sitemesh3/src/main/resources/struts.xml                      |  4 +---
 .../WEB-INF/decorators/{decorator.html => decorator1.html}   |  1 +
 .../WEB-INF/decorators/{decorator.html => decorator2.html}   |  1 +
 sitemesh3/src/main/webapp/WEB-INF/hello.jsp                  |  8 +-------
 sitemesh3/src/main/webapp/WEB-INF/index.jsp                  |  7 +++++++
 sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml              | 12 ++++++++++--
 sitemesh3/src/main/webapp/index.html                         |  2 +-
 7 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/sitemesh3/src/main/resources/struts.xml b/sitemesh3/src/main/resources/struts.xml
index e95c041..e117812 100644
--- a/sitemesh3/src/main/resources/struts.xml
+++ b/sitemesh3/src/main/resources/struts.xml
@@ -9,9 +9,7 @@
     <package name="default" extends="struts-default">
         <default-action-ref name="index"/>
         <action name="index">
-            <result type="redirectAction">
-                <param name="actionName">hello</param>
-            </result>
+            <result>/WEB-INF/index.jsp</result>
         </action>
 
       <action name="hello">
diff --git a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator1.html
similarity index 85%
copy from sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html
copy to sitemesh3/src/main/webapp/WEB-INF/decorators/decorator1.html
index eeb64a1..01b2f66 100644
--- a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html
+++ b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator1.html
@@ -4,6 +4,7 @@
     <sitemesh:write property="head"/>
 </head>
 <body>
+<h1>Decorator 1</h1>
 <sitemesh:write property="body"/>
 </body>
 </html>
\ No newline at end of file
diff --git a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html
similarity index 85%
rename from sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html
rename to sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html
index eeb64a1..2caccec 100644
--- a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html
+++ b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html
@@ -4,6 +4,7 @@
     <sitemesh:write property="head"/>
 </head>
 <body>
+<h1>Decorator 2</h1>
 <sitemesh:write property="body"/>
 </body>
 </html>
\ No newline at end of file
diff --git a/sitemesh3/src/main/webapp/WEB-INF/hello.jsp b/sitemesh3/src/main/webapp/WEB-INF/hello.jsp
index a4aa404..4887549 100644
--- a/sitemesh3/src/main/webapp/WEB-INF/hello.jsp
+++ b/sitemesh3/src/main/webapp/WEB-INF/hello.jsp
@@ -1,10 +1,6 @@
 <%@ page contentType="text/html; charset=UTF-8" %>
 <%@ taglib prefix="s" uri="/struts-tags" %>
-<html>
-<head>
-    <title>SiteMesh example: Hello World</title>
-</head>
-<body>
+
 <h2><s:text name="%{getText('HelloWorld.message')}"/></h2>
 
 <h3>Languages</h3>
@@ -26,5 +22,3 @@
         <code>EL: ${url}</code>
     </li>
 </ul>
-</body>
-</html>
diff --git a/sitemesh3/src/main/webapp/WEB-INF/index.jsp b/sitemesh3/src/main/webapp/WEB-INF/index.jsp
new file mode 100644
index 0000000..4375047
--- /dev/null
+++ b/sitemesh3/src/main/webapp/WEB-INF/index.jsp
@@ -0,0 +1,7 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<s:url var="url" action="hello">
+    <s:param name="request_locale">en</s:param>
+</s:url>
+<s:a href="%{url}">English</s:a>
diff --git a/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml b/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml
index 77fbc3b..ad05d21 100644
--- a/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml
+++ b/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml
@@ -1,3 +1,11 @@
 <sitemesh>
-    <mapping path="/*" decorator="decorator.html"/>
-</sitemesh>
\ No newline at end of file
+    <!-- compact version -->
+    <mapping path="/" decorator="decorator1.html"/>
+    <mapping path="/index" decorator="decorator1.html"/>
+
+    <!-- full version (allows multiple decorators for a given path) -->
+    <mapping>
+        <path>/hello*</path>
+        <decorator>decorator2.html</decorator>
+    </mapping>
+</sitemesh>
diff --git a/sitemesh3/src/main/webapp/index.html b/sitemesh3/src/main/webapp/index.html
index dc2bbd0..abdee36 100644
--- a/sitemesh3/src/main/webapp/index.html
+++ b/sitemesh3/src/main/webapp/index.html
@@ -1,7 +1,7 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <html>
 <head>
-    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=example/HelloWorld.action">
+    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=index.action">
 </head>
 
 <body>