From 848e7c1a4e7b60bc722b37a302e06d3b0a6e2419 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Fri, 11 Oct 2024 08:12:53 +0200 Subject: [PATCH] Extends example with Sitemesh 3 to support multiple decorators --- sitemesh3/pom.xml | 4 ++ .../examples/sitemesh3/HelloAction.java | 43 +++++++++++++++++++ sitemesh3/src/main/resources/struts.xml | 14 +++--- .../webapp/WEB-INF/decorators/decorator.html | 3 +- .../webapp/WEB-INF/decorators/decorator1.html | 10 +++++ .../webapp/WEB-INF/decorators/decorator2.html | 10 +++++ sitemesh3/src/main/webapp/WEB-INF/error.jsp | 16 +++++++ sitemesh3/src/main/webapp/WEB-INF/hello.jsp | 27 ------------ sitemesh3/src/main/webapp/WEB-INF/hello1.jsp | 18 ++++++++ sitemesh3/src/main/webapp/WEB-INF/hello2.jsp | 18 ++++++++ sitemesh3/src/main/webapp/WEB-INF/index.jsp | 14 ++++++ .../src/main/webapp/WEB-INF/sitemesh3.xml | 5 ++- sitemesh3/src/main/webapp/index.html | 2 +- 13 files changed, 148 insertions(+), 36 deletions(-) create mode 100644 sitemesh3/src/main/java/org/apache/struts/examples/sitemesh3/HelloAction.java create mode 100644 sitemesh3/src/main/webapp/WEB-INF/decorators/decorator1.html create mode 100644 sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html create mode 100644 sitemesh3/src/main/webapp/WEB-INF/error.jsp delete mode 100644 sitemesh3/src/main/webapp/WEB-INF/hello.jsp create mode 100644 sitemesh3/src/main/webapp/WEB-INF/hello1.jsp create mode 100644 sitemesh3/src/main/webapp/WEB-INF/hello2.jsp create mode 100644 sitemesh3/src/main/webapp/WEB-INF/index.jsp diff --git a/sitemesh3/pom.xml b/sitemesh3/pom.xml index 7f31a857..fd25c403 100644 --- a/sitemesh3/pom.xml +++ b/sitemesh3/pom.xml @@ -13,6 +13,10 @@ war + + 7.0.0-M11-SNAPSHOT + + org.sitemesh diff --git a/sitemesh3/src/main/java/org/apache/struts/examples/sitemesh3/HelloAction.java b/sitemesh3/src/main/java/org/apache/struts/examples/sitemesh3/HelloAction.java new file mode 100644 index 00000000..f26691e3 --- /dev/null +++ b/sitemesh3/src/main/java/org/apache/struts/examples/sitemesh3/HelloAction.java @@ -0,0 +1,43 @@ +package org.apache.struts.examples.sitemesh3; + +import org.apache.struts2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; + +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; + +public class HelloAction extends ActionSupport { + + private static final Map DECORATORS = Collections.unmodifiableSortedMap(new TreeMap<>() {{ + put("1", "Decorator 1"); + put("2", "Decorator 2"); + put("3", "Exclude from decorating"); + }}); + + private String decorator; + + @Override + public String execute() throws Exception { + if ("1".equals(decorator)) { + return SUCCESS; + } else if ("2".equals(decorator)) { + return "other"; + } + addActionError("Wrong decorator: " + decorator); + return ERROR; + } + + public String getDecorator() { + return decorator; + } + + @StrutsParameter + public void setDecorator(String decorator) { + this.decorator = decorator; + } + + public Map getDecorators() { + return DECORATORS; + } +} diff --git a/sitemesh3/src/main/resources/struts.xml b/sitemesh3/src/main/resources/struts.xml index e95c0411..935d1b82 100644 --- a/sitemesh3/src/main/resources/struts.xml +++ b/sitemesh3/src/main/resources/struts.xml @@ -4,19 +4,21 @@ "https://struts.apache.org/dtds/struts-6.0.dtd"> + + - - hello - + /WEB-INF/index.jsp - - /WEB-INF/hello.jsp - + + /WEB-INF/hello1.jsp + /WEB-INF/hello2.jsp + /WEB-INF/error.jsp + diff --git a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html index eeb64a1c..2d7835d8 100644 --- a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html +++ b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html @@ -4,6 +4,7 @@ +

Default Decorator

- \ No newline at end of file + diff --git a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator1.html b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator1.html new file mode 100644 index 00000000..bbaf9082 --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator1.html @@ -0,0 +1,10 @@ + + + <sitemesh:write property="title"/> + + + +

Decorator 1

+ + + diff --git a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html new file mode 100644 index 00000000..57a92c5f --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html @@ -0,0 +1,10 @@ + + + <sitemesh:write property="title"/> + + + +

Decorator 2

+ + + diff --git a/sitemesh3/src/main/webapp/WEB-INF/error.jsp b/sitemesh3/src/main/webapp/WEB-INF/error.jsp new file mode 100644 index 00000000..19bf8089 --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/error.jsp @@ -0,0 +1,16 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + SiteMesh example: error + + +

SiteMesh example: error

+ + + + + +Hello + + diff --git a/sitemesh3/src/main/webapp/WEB-INF/hello.jsp b/sitemesh3/src/main/webapp/WEB-INF/hello.jsp deleted file mode 100644 index 953de73f..00000000 --- a/sitemesh3/src/main/webapp/WEB-INF/hello.jsp +++ /dev/null @@ -1,27 +0,0 @@ -<%@ page contentType="text/html; charset=UTF-8" %> -<%@ taglib prefix="s" uri="/struts-tags" %> - - - SiteMesh example: Hello World - - -

- -

Languages

-
    -
  • - - en - - English -
  • -
  • - - es - - Espanol -
  • -
-EL: ${url} - - diff --git a/sitemesh3/src/main/webapp/WEB-INF/hello1.jsp b/sitemesh3/src/main/webapp/WEB-INF/hello1.jsp new file mode 100644 index 00000000..dee6bedd --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/hello1.jsp @@ -0,0 +1,18 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + SiteMesh example: Hello 1 with Decorator 1 + + +

SiteMesh example: Hello 1 with Decorator 1

+

Decorators

+
+ + + + +
+

Selected decorator:

+ + \ No newline at end of file diff --git a/sitemesh3/src/main/webapp/WEB-INF/hello2.jsp b/sitemesh3/src/main/webapp/WEB-INF/hello2.jsp new file mode 100644 index 00000000..f9a2da9b --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/hello2.jsp @@ -0,0 +1,18 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + SiteMesh example: Hello 2 with Decorator 2 + + +

SiteMesh example: Hello 2 with Decorator 2

+

Decorators

+
+ + + + +
+

Selected decorator:

+ + \ No newline at end of file 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 00000000..0bbc7cf1 --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/index.jsp @@ -0,0 +1,14 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + SiteMesh example: Index + + +

SiteMesh example: Index with Default Decorator

+ + + +Hello + + \ No newline at end of file diff --git a/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml b/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml index 77fbc3be..f8803620 100644 --- a/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml +++ b/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml @@ -1,3 +1,6 @@ - \ No newline at end of file + + + + diff --git a/sitemesh3/src/main/webapp/index.html b/sitemesh3/src/main/webapp/index.html index dc2bbd02..abdee369 100644 --- a/sitemesh3/src/main/webapp/index.html +++ b/sitemesh3/src/main/webapp/index.html @@ -1,7 +1,7 @@ - +