-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extends example with Sitemesh 3 to support multiple decorators
- Loading branch information
1 parent
f6dcf44
commit 57a6130
Showing
13 changed files
with
148 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
sitemesh3/src/main/java/org/apache/struts/examples/sitemesh3/HelloAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> 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<String, String> getDecorators() { | ||
return DECORATORS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
sitemesh3/src/main/webapp/WEB-INF/decorators/decorator1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
<head> | ||
<title><sitemesh:write property="title"/></title> | ||
<sitemesh:write property="head"/> | ||
</head> | ||
<body> | ||
<h1>Decorator 1</h1> | ||
<sitemesh:write property="body"/> | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
<head> | ||
<title><sitemesh:write property="title"/></title> | ||
<sitemesh:write property="head"/> | ||
</head> | ||
<body> | ||
<h1>Decorator 2</h1> | ||
<sitemesh:write property="body"/> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%@ page contentType="text/html; charset=UTF-8" %> | ||
<%@ taglib prefix="s" uri="/struts-tags" %> | ||
<html> | ||
<head> | ||
<title>SiteMesh example: error</title> | ||
</head> | ||
<body> | ||
<h2>SiteMesh example: error</h2> | ||
<s:actionerror/> | ||
|
||
<s:url var="url" action="hello"> | ||
<s:param name="decorator" value="1"/> | ||
</s:url> | ||
<s:a href="%{url}">Hello</s:a> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<%@ page contentType="text/html; charset=UTF-8" %> | ||
<%@ taglib prefix="s" uri="/struts-tags" %> | ||
<html> | ||
<head> | ||
<title>SiteMesh example: Hello 1 with Decorator 1</title> | ||
</head> | ||
<body> | ||
<h2>SiteMesh example: Hello 1 with Decorator 1</h2> | ||
<h3>Decorators</h3> | ||
<div> | ||
<s:form action="hello" method="get"> | ||
<s:select name="decorator" list="decorators"/> | ||
<s:submit value="Decorate"/> | ||
</s:form> | ||
</div> | ||
<p>Selected decorator: <s:property value="decorator"/></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<%@ page contentType="text/html; charset=UTF-8" %> | ||
<%@ taglib prefix="s" uri="/struts-tags" %> | ||
<html> | ||
<head> | ||
<title>SiteMesh example: Hello 2 with Decorator 2</title> | ||
</head> | ||
<body> | ||
<h2>SiteMesh example: Hello 2 with Decorator 2</h1> | ||
<h3>Decorators</h3> | ||
<div> | ||
<s:form action="hello" method="get"> | ||
<s:select name="decorator" list="decorators"/> | ||
<s:submit value="Decorate"/> | ||
</s:form> | ||
</div> | ||
<p>Selected decorator: <s:property value="decorator"/></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<%@ page contentType="text/html; charset=UTF-8" %> | ||
<%@ taglib prefix="s" uri="/struts-tags" %> | ||
<html> | ||
<head> | ||
<title>SiteMesh example: Index</title> | ||
</head> | ||
<body> | ||
<h2>SiteMesh example: Index with Default Decorator</h2> | ||
<s:url var="url" action="hello"> | ||
<s:param name="decorator" value="1"/> | ||
</s:url> | ||
<s:a href="%{url}">Hello</s:a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<sitemesh> | ||
<mapping path="/*" decorator="decorator.html"/> | ||
</sitemesh> | ||
<mapping path="/WEB-INF/error.jsp" exclude="true"/> | ||
<mapping path="/WEB-INF/hello1.jsp" decorator="decorator1.html"/> | ||
<mapping path="/WEB-INF/hello2.jsp" decorator="decorator2.html"/> | ||
</sitemesh> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters