blob: 1396a70a36979d3edcd11b6ddf290019f3379d17 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>Apache Wicket - Wicket Velocity</title>
<link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen" />
<!--[if lt ie 7]>
<link rel="stylesheet" href="/css/ie.css" type="text/css" media="screen" />
<![endif]-->
<link rel="shortcut icon" href="/favicon.ico" type="image/vnd.microsoft.icon" />
<link rel="alternate" type="application/atom+xml" href="/atom.xml" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
<div id="container">
<div id="content">
<div id="header"><a href="/"><h1 id="logo"><span>Apache Wicket</span></h1></a></div>
<div id="navigation">
<h5><a name="Navigation-Wicket"></a>Meet Wicket</h5>
<ul>
<li>
<a href="/" title="Index">Home</a>
</li>
<li>
<a href="/meet/introduction.html" title="Introduction">Introduction</a>
</li>
<li>
<a href="/meet/features.html" title="Features">Features</a>
</li>
<li>
<a href="/meet/buzz.html" title="Buzz">Buzz</a>
</li>
<li>
<a href="/meet/vision.html" title="Vision">Vision</a>
</li>
<li>
<a href="/meet/blogs.html" title="Blogs">Blogs</a>
</li>
</ul>
<h5>
<a name="Navigation-GettingStarted" id="Navigation-GettingStarted"></a>Get Started
</h5>
<ul>
<li>
<a href="/start/download.html" title="Download Wicket">Download Wicket</a>
</li>
<li>
<a href="/start/quickstart.html" title="Getting started via a Maven Archetype">Quickstart</a>
</li>
<li>
<a href="http://www.jweekend.com/dev/LegUp" rel="nofollow">More archetypes</a>
</li>
<li>
<a href="/help" title="Get help">Get help</a>
</li>
<li>
<a href="/help/email.html" title="Wicket Mailing Lists">Mailing Lists</a>
</li>
</ul>
<h5>
<a name="Navigation-Documentation" id="Navigation-Documentation"></a>Learn
</h5>
<ul>
<li>
<a href="/start/userguide.html" title="User Guide">User Guide</a>
</li>
<li>
<a href="/learn/examples" title="Examples">Examples</a>
</li>
<li>
<a href="http://www.wicket-library.com/wicket-examples/compref/">Components</a>
</li>
<li>
<a href="/learn/projects/" title="Projects extending basic Wicket">Projects</a>
</li>
<li>
<a href="https://cwiki.apache.org/confluence/display/WICKET">Wiki</a>
</li>
<li>
<a href="https://cwiki.apache.org/confluence/display/WICKET/Reference+library">Reference guide</a>
</li>
<li>
<a href="/learn/books" title="Books">Books</a>
</li>
<li>
<a href="/learn/ides.html" title="IDEs">IDEs</a>
</li>
</ul>
<h5>
<a name="Navigation-Releases" id="Navigation-Releases"></a>Releases
</h5>
<ul>
<li>
<a href="http://www.apache.org/dyn/closer.cgi/wicket/6.20.0">Wicket 6.20</a>
</li>
<li>
<a href="http://www.apache.org/dyn/closer.cgi/wicket/1.5.13">Wicket 1.5</a>
</li>
<li>
<a href="http://www.apache.org/dyn/closer.cgi/wicket/1.4.23">Wicket 1.4</a>
</li>
<li>
<a href="http://www.apache.org/dyn/closer.cgi/wicket/1.3.7">Wicket 1.3</a>
</li>
<li>
<a href="http://wicket.sf.net/wicket-1.2" class="external-link" rel="nofollow">Wicket 1.2</a>
</li>
<li>
<a href="http://wicket.sf.net/wicket-1.1" class="external-link" rel="nofollow">Wicket 1.1</a>
</li>
<li>
<a href="http://wicket.sf.net/wicket-1.0" class="external-link" rel="nofollow">Wicket 1.0</a>
</li>
</ul>
<h5>
<a name="Navigation-Docs" id="Navigation-Docs"></a>API Docs
</h5>
<ul>
<li>
<a href="http://ci.apache.org/projects/wicket/apidocs/6.x/" title="JavaDocs of Apache Wicket 6.x">Wicket 6.x</a>
</li>
<li>
<a href="http://ci.apache.org/projects/wicket/apidocs/1.5.x/" title="JavaDocs of Apache Wicket 1.5.x">Wicket 1.5</a>
</li>
<li>
<a href="http://ci.apache.org/projects/wicket/apidocs/1.4.x" title="JavaDocs of Apache Wicket 1.4.x">Wicket 1.4</a>
</li>
<li>
<a href="http://ci.apache.org/projects/wicket/apidocs/1.3.x" title="JavaDocs of Apache Wicket 1.3.x">Wicket 1.3</a>
</li>
</ul>
<h5>Wicket 7.x</h5>
<ul>
<li>
<a href="http://www.apache.org/dyn/closer.cgi/wicket/7.0.0-M6">Download M6</a>
</li>
<li>
<a href="https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+7.0">Migration guide</a>
</li>
<li>
<a href="http://ci.apache.org/projects/wicket/apidocs/7.x/" title="JavaDocs of Apache Wicket 7.x">API Docs 7.x</a>
</li>
</ul>
<h5>
<a name="Navigation-Developers" id="Navigation-Developers"></a>Contribute
</h5>
<ul>
<li>
<a href="/contribute/write.html" title="Writing documentation">Writing docs</a>
</li>
<li>
<a href="/contribute/build.html" title="Building from SVN">Build Wicket</a>
</li>
<li>
<a href="/contribute/patch.html" title="Provide a patch">Provide a patch</a>
</li>
<li>
<a href="/contribute/release.html" title="Release Wicket">Release Wicket</a>
</li>
<li>
<a href="https://fisheye6.atlassian.com/browse/wicket-git" title="Git Overview" class="external-link" rel="nofollow">Fisheye</a>
</li>
</ul>
<h5>
<a name="Navigation-Apache" id="Navigation-Apache"></a>Apache
</h5>
<ul>
<li>
<a href="http://www.apache.org/" class="external-link" rel="nofollow">Apache</a>
</li>
<li>
<a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a>
</li>
<li>
<a href="http://www.apache.org/foundation/sponsorship.html" class="external-link" rel="nofollow">Sponsorship</a>
</li>
<li>
<a href="http://apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a>
</li>
<li>
<a href="/apache/friends.html" title="Apache projects using Wicket">Friends</a>
</li>
</ul>
</div>
<div id="contentbody">
<h1>Wicket Velocity</h1>
<p>Provides a specialized panel and some related utilities that enables users to
work with <a href="http://velocity.apache.org">Apache Velocity</a> and <a href="http://wicket.apache.org">Apache
Wicket</a>. Particularly useful for simple CMS like
applications.</p>
<h2 id="contents">Contents</h2>
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#installing">Installing</a></li>
</ul>
<h2 id="introduction">Introduction</h2>
<p>Velocity brings a templating language to your users. You can let them create
conditional markup, use loops and do all other things made possible by
Velocity.</p>
<p>Velocity templates look like the following:</p>
<div class="highlight"><pre><code class="language-html" data-lang="html">#set ($foo = &quot;deoxyribonucleic acid&quot;)
#set ($bar = &quot;ribonucleic acid&quot;)
#if ($foo == $bar)
In this case it&#39;s clear they aren&#39;t equivalent. So...
#else
They are not equivalent and this will be the output.
#end</code></pre></div>
<p>Read
<a href="http://velocity.apache.org/engine/releases/velocity-1.4/user-guide.html">more</a>
about the Velocity template language.</p>
<p>This project allows you to use Velocity templates as a component within your
Wicket pages, and let them live next to Wicket components. A typical usecase
would be to enable your users to embed Velocity templates in your application
and using that as a type of portlet.</p>
<p>The main component for the Veloticy/Wicket integration is the
<a href="http://wicket.apache.org/docs/1.4/org/apache/wicket/velocity/markup/html/VelocityPanel.html"><code>VelocityPanel</code></a>.</p>
<h2 id="example">Example</h2>
<p>Showing Hello, World using Velocity in a Wicket application, embedded in a
Wicket page.</p>
<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt">&lt;h2&gt;</span>This is a Velocity template<span class="nt">&lt;/h2&gt;</span>
<span class="nt">&lt;p&gt;</span>The secret message is: $message<span class="nt">&lt;/p&gt;</span></code></pre></div>
<p>In this template we want to replace the string <code>$message</code> with the text
“Hello, World!”. <code>$message</code> is Velocity markup denoting a variable that is
taken from the context that is provided to the Velocity rendering engine.</p>
<p>To use Velocity in your Wicket pages we provide a <code>VelocityPanel</code> which
enables you to generate parts of your page using Velocity markup. Adding the
panel to your Wicket page is shown in the following example:</p>
<div class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="nf">VelocityPage</span><span class="o">()</span> <span class="o">{</span>
<span class="n">HashMap</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">String</span><span class="o">&gt;</span> <span class="n">values</span> <span class="o">=</span> <span class="k">new</span> <span class="n">HashMap</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">String</span><span class="o">&gt;();</span>
<span class="n">values</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;message&quot;</span><span class="o">,</span> <span class="s">&quot;Hello, World!&quot;</span><span class="o">);</span>
<span class="n">Model</span><span class="o">&lt;</span><span class="n">HashMap</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">String</span><span class="o">&gt;&gt;</span> <span class="n">context</span> <span class="o">=</span> <span class="n">Model</span><span class="o">.</span><span class="na">of</span><span class="o">(</span><span class="n">values</span><span class="o">);</span>
<span class="n">UrlResourceStream</span> <span class="n">template</span> <span class="o">=</span> <span class="k">new</span> <span class="nf">UrlResourceStream</span><span class="o">(</span><span class="n">getClass</span><span class="o">().</span><span class="na">getResource</span><span class="o">(</span><span class="s">&quot;test.html&quot;</span><span class="o">));</span>
<span class="n">add</span><span class="o">(</span><span class="n">VelocityPanel</span><span class="o">.</span><span class="na">forTemplateResource</span><span class="o">(</span><span class="s">&quot;velocityPanel&quot;</span><span class="o">,</span> <span class="n">context</span><span class="o">,</span> <span class="n">template</span><span class="o">));</span>
<span class="o">}</span></code></pre></div>
<p><code>VelocityPanel.forTemplateResource</code> creates a <code>VelocityPanel</code> and sets up the
engine such that the context is merged with the template with each render.</p>
<p>The markup of the page is quite simple: adding a VelocityPanel is as simple
as using a <code>div</code> and attaching a <code>wicket:identifier</code> to it. The following
example shows this.</p>
<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="cp">&lt;!DOCTYPE html&gt;</span>
<span class="nt">&lt;h1&gt;</span>This is a test page for Velocity<span class="nt">&lt;/h1&gt;</span>
<span class="nt">&lt;div</span> <span class="na">wicket:id=</span><span class="s">&quot;velocityPanel&quot;</span><span class="nt">&gt;&lt;/div&gt;</span></code></pre></div>
<h2 id="installing">Installing</h2>
<p>Installing Wicket Velocity can be done through adding a dependency in your
project’s Maven pom, or by putting the wicket-velocity.jar and the required
dependencies in your projects classpath.</p>
<h3 id="using-maven">Using Maven</h3>
<p>Add the following dependency to your pom:</p>
<div class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.wicket<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>wicket-velocity<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>6.20.0<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span></code></pre></div>
<h3 id="required-dependencies">Required dependencies</h3>
<p>Wicket Velocity requires the following jar files to be on your classpath:</p>
<ul>
<li>Wicket</li>
<li>Wicket Velocity</li>
<li>Apache Velocity</li>
</ul>
<p>Check the <a href="http://velocity.apache.org">Apache Velocity project</a> to find out
which other dependencies you need.</p>
</div>
<div id="clearer"></div>
<div id="footer"><span>
Copyright &copy; 2015 &mdash; The Apache Software Foundation. Apache Wicket,
Wicket, Apache, the Apache feather logo, and the Apache Wicket project logo
are trademarks of The Apache Software Foundation. All other marks mentioned
may be trademarks or registered trademarks of their respective owners.
</span></div>
</div>
</div>
</body>
</html>