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 <lukaszlen...@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>

Reply via email to