1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
<html>
<head>
<title>Velocity Decorators</title>
</head>
<body>
As of SiteMesh 2.0.2 <a href="http://jakarta.apache.org/velocity/">Velocity</a> (.vm)
decorators are supported.
<p>Here is an example of how such a decorator (e.g. /decorators/main.vm) might look like:</p>
<pre style="border: 1px solid #999999; padding: 5px">
#parse ("/includes/decorators/header.vm")
<h2><b>$title</b></h2>
<b>$head</b>
<img src="<b>$base</b>/images/logo.gif" border="0">
<td valign="top" class="body">
<div class="header">
<span class="pagetitle"><b>$title</b></span>
</div>
<b>$body</b>
</td>
#parse ("/includes/decorators/footer.vm")
</pre>
<h3>Installation</h3>
<ul>
<li>Download <a
href="http://jakarta.apache.org/velocity/">Velocity</a> 1.3.1 or
higher and copy it into <b><code>[web-app]/WEB-INF/lib</code></b>.
The SiteMesh distribution comes with <b>velocity-dep-1.3.1.jar</b>.</p></li>
<li>Download <a
href="http://jakarta.apache.org/velocity/tools/">VelocityTools</a> 1.1
and copy it into <b><code>[web-app]/WEB-INF/lib</code></b>.
The SiteMesh distribution comes with <b>velocity-tools-view-1.1.jar</b>.</p></li>
<li>Download <a
href="http://jakarta.apache.org/commons/collections/">Commons Collections</a> 2.1 or
higher and copy it into <b><code>[web-app]/WEB-INF/lib</code></b>.
The SiteMesh distribution comes with <b>commons-collections.jar</b>.</p></li>
<li>Add the following to <b><code>[web-app]/WEB-INF/web.xml</code></b>
within the <b><code><web-app></code></b> tag:</li>
</ul>
<pre style="border: 1px solid #999999; padding: 5px">
<servlet>
<servlet-name><b>sitemesh-velocity</b></servlet-name>
<servlet-class><b>com.opensymphony.module.sitemesh.velocity.VelocityDecoratorServlet</b></servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-velocity</servlet-name>
<url-pattern><b>*.vm</b></url-pattern>
</servlet-mapping>
</pre>
<ul>
<li>Modify <b><code>decorators.xml</code></b> to reference a .vm
decorator.</li>
</ul>
<p>A working example is included with the SiteMesh distribution, under the <a href="https://sitemesh.dev.java.net/source/browse/sitemesh/src/example-webapp/">src/example-webapp</a> directory.</p>
<h3>Context</h3>
VelocityDecoratorServlet puts some things into the context object that you should be aware of:
<table border="0" cellspacing="10">
<tr>
<td valign="top"><strong>$request</strong> (from <a href="http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/view/servlet/VelocityViewServlet.html">VelocityViewServlet</a>)</td>
<td>The HttpServletRequest object</td>
</tr>
<tr>
<td valign="top"><strong>$response</strong> (from <a href="http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/view/servlet/VelocityViewServlet.html">VelocityViewServlet</a>)</td>
<td>The HttpServletResponse object</td>
</tr>
<tr>
<td valign="top"><strong>$session</strong> (from <a href="http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/view/servlet/VelocityViewServlet.html">VelocityViewServlet</a>)</td>
<td>The HttpSession object</td>
</tr>
<tr>
<td valign="top"><strong>$application</strong> (from <a href="http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/view/servlet/VelocityViewServlet.html">VelocityViewServlet</a>)</td>
<td>The ServletContext object</td>
</tr>
<tr>
<td valign="top"><strong>$base</strong></td>
<td>request.getContextPath()</td>
</tr>
<tr>
<td valign="top"><strong>$title</strong></td>
<td>Parsed page title (<title>...<title>)</td>
</tr>
<tr>
<td valign="top"><strong>$head</strong></td>
<td>Parsed page head</td>
</tr>
<tr>
<td valign="top"><strong>$body</strong></td>
<td>Parsed page body</td>
</tr>
<tr>
<td valign="top"><strong>$page</strong></td>
<td>SiteMesh's internal Page object</td>
</tr>
<tr>
<td valign="top"><strong>Anything else</strong></td>
<td>Search for the attribute by that name in the request, session and application scopes</td>
</tr>
</table>
</body>
</html>
|