Skip to content

Commit

Permalink
Extends example with Sitemesh 3 to support multiple decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Nov 14, 2024
1 parent f6dcf44 commit 0e91552
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
4 changes: 1 addition & 3 deletions sitemesh3/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<sitemesh:write property="head"/>
</head>
<body>
<h1>Decorator 1</h1>
<sitemesh:write property="body"/>
</body>
</html>
</html>
10 changes: 10 additions & 0 deletions sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html
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>
13 changes: 5 additions & 8 deletions sitemesh3/src/main/webapp/WEB-INF/hello.jsp
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -14,14 +10,15 @@
<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>
EL: ${url}
</body>
</html>
7 changes: 7 additions & 0 deletions sitemesh3/src/main/webapp/WEB-INF/index.jsp
Original file line number Diff line number Diff line change
@@ -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>
12 changes: 10 additions & 2 deletions sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<sitemesh>
<mapping path="/*" decorator="decorator.html"/>
</sitemesh>
<!-- 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>
2 changes: 1 addition & 1 deletion sitemesh3/src/main/webapp/index.html
Original file line number Diff line number Diff line change
@@ -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>
Expand Down

0 comments on commit 0e91552

Please sign in to comment.