http://git-wip-us.apache.org/repos/asf/wicket-site/blob/8cc72bad/_site/learn/examples/dropdownchoice.html ---------------------------------------------------------------------- diff --git a/_site/learn/examples/dropdownchoice.html b/_site/learn/examples/dropdownchoice.html new file mode 100644 index 0000000..f180bc9 --- /dev/null +++ b/_site/learn/examples/dropdownchoice.html @@ -0,0 +1,369 @@ +<!DOCTYPE html> +<html> +<head> + <title>Apache Wicket - Using the DropDownChoice component</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.19.0">Wicket 6.19</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-M5">Download M5</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>Using the DropDownChoice component</h1> + <p>One of the most problematic components for beginners of Wicket is the +<code>DropDownChoice</code> component. In this example we will work the component to +give a little more insight into its workings. This example requires that you +have some understanding of the Wicket component model (nothing fancy though, +but you might want to read the other examples first), and the Model concept +used in Wicket (you can read more on models +<a href="https://cwiki.apache.org/confluence/display/WICKET/Working+with+Wicket+models">here</a>).</p> + +<h2 id="the-example-domain">The example domain</h2> + +<p>The <code>DropDownChoice</code> component is typically used <em>inside</em> a form. This +example will expand on that usage. The component is particularly designed to +work with objects. So letâs say we have a list of people and we want to +select the manager of an employee.</p> + +<div class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Person</span> <span class="o">{</span> + <span class="kd">private</span> <span class="n">Long</span> <span class="n">id</span><span class="o">;</span> + <span class="kd">private</span> <span class="n">String</span> <span class="n">name</span><span class="o">;</span> + <span class="kd">private</span> <span class="n">Person</span> <span class="n">managedBy</span><span class="o">;</span> + + <span class="c1">// ... insert getters and setters</span> + + <span class="cm">/**</span> +<span class="cm"> * Used to display the person.</span> +<span class="cm"> */</span> + <span class="kd">public</span> <span class="n">String</span> <span class="nf">toString</span><span class="o">()</span> <span class="o">{</span> + <span class="k">return</span> <span class="n">name</span><span class="o">;</span> + <span class="o">}</span> + + <span class="cm">/**</span> +<span class="cm"> * Gets the list of possible managers from the database.</span> +<span class="cm"> */</span> + <span class="kd">public</span> <span class="kd">static</span> <span class="n">List</span><span class="o"><</span><span class="n">Person</span><span class="o">></span> <span class="nf">getManagers</span><span class="o">()</span> <span class="o">{</span> + <span class="c1">// gets the managers from the database</span> + <span class="o">}</span> +<span class="o">}</span></code></pre></div> + +<h2 id="the-assign-manager-page">The assign manager page</h2> + +<p>Next we want to create a page where we assign a manager to an employee. This +is how the page would look like in HTML:</p> + +<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><html></span> +<span class="nt"><body></span> +<span class="nt"><form</span> <span class="na">wicket:id=</span><span class="s">"form"</span><span class="nt">></span> +<span class="nt"><h1></span>Assign manager<span class="nt"></h1></span> +<span class="nt"><table></span> +<span class="nt"><tr></span> + <span class="nt"><th></span>Name<span class="nt"></th></span> + <span class="nt"><td</span> <span class="na">wicket:id=</span><span class="s">"name"</span><span class="nt">></span>Some employee<span class="nt"></td></span> +<span class="nt"></tr></span> +<span class="nt"><tr></span> + <span class="nt"><th></span>Managed by<span class="nt"></th></span> + <span class="nt"><td><select</span> <span class="na">wicket:id=</span><span class="s">"managedBy"</span><span class="nt">></span> + <span class="nt"><option></span>Some Person<span class="nt"></option></span> + <span class="nt"><option></span>Some Other Person<span class="nt"></option></span> + <span class="nt"></select></span> + <span class="nt"></td></span> +<span class="nt"></tr></span> +<span class="nt"><tr><td</span> <span class="na">colspan=</span><span class="s">"2"</span><span class="nt">><input</span> <span class="na">type=</span><span class="s">"submit"</span> <span class="na">value=</span><span class="s">"Save"</span><span class="nt">/></td></tr></span> +<span class="nt"></table></span> +<span class="nt"></form></span> +<span class="nt"></body></span> +<span class="nt"></html></span></code></pre></div> + +<p>This page has three components:</p> + +<ul> + <li>a form (needed to process the input),</li> + <li>a label (to show the name of the employee) and </li> + <li>a select box for picking the manager.</li> +</ul> + +<p>We will focus on the select box, because that will be our <code>DropDownChoice</code>. +The <code><option></code> tags are there for preview, our component will replace them +with the generated choices.</p> + +<p>Letâs see how the page looks like from the Java side:</p> + +<div class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">AssignManagerPage</span> <span class="kd">extends</span> <span class="n">WebPage</span> <span class="o">{</span> + <span class="kd">public</span> <span class="nf">AssignManagerPage</span><span class="o">(</span><span class="n">Person</span> <span class="n">employee</span><span class="o">)</span> <span class="o">{</span> + <span class="n">Form</span> <span class="n">form</span> <span class="o">=</span> <span class="k">new</span> <span class="nf">Form</span><span class="o">(</span><span class="s">"form"</span><span class="o">);</span> + <span class="n">add</span><span class="o">(</span><span class="n">form</span><span class="o">);</span> + <span class="n">form</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="k">new</span> <span class="nf">Label</span><span class="o">(</span><span class="s">"name"</span><span class="o">,</span> <span class="k">new</span> <span class="n">PropertyModel</span><span class="o"><</span><span class="n">String</span><span class="o">>(</span><span class="n">employee</span><span class="o">,</span> <span class="s">"name"</span><span class="o">)));</span> + + <span class="n">DropDownChoice</span><span class="o"><</span><span class="n">Person</span><span class="o">></span> <span class="n">ddc</span> <span class="o">=</span> + <span class="k">new</span> <span class="n">DropDownChoice</span><span class="o"><</span><span class="n">Person</span><span class="o">>(</span><span class="s">"name"</span><span class="o">,</span> + <span class="k">new</span> <span class="n">PropertyModel</span><span class="o"><</span><span class="n">Person</span><span class="o">>(</span><span class="n">employee</span><span class="o">,</span> <span class="s">"managedBy"</span><span class="o">),</span> + <span class="k">new</span> <span class="n">LoadableDetachableModel</span><span class="o"><</span><span class="n">List</span><span class="o"><</span><span class="n">Person</span><span class="o">>>()</span> <span class="o">{</span> + <span class="nd">@Override</span> + <span class="kd">protected</span> <span class="n">Object</span> <span class="nf">load</span><span class="o">()</span> <span class="o">{</span> + <span class="k">return</span> <span class="n">Person</span><span class="o">.</span><span class="na">getManagers</span><span class="o">();</span> + <span class="o">}</span> + <span class="o">}</span> + <span class="o">);</span> + <span class="n">form</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">ddc</span><span class="o">));</span> + <span class="o">}</span> +<span class="o">}</span></code></pre></div> + +<p>In this example you see that we add the <code>DropDownChoice</code> to the form, and +provide it with 3 parameters. The first is the component identifier. The +second is the item that needs to be updated, in this case the <code>managedBy</code> +field of the <code>employee</code>. The third parameter is a <code>LoadableDetachableModel</code> +that retrieves the list of available choices.</p> + +<p>Note that the <code>DropDownChoice</code> component has many constructors, and that you +need to read the JavaDoc documentation to pick the right one for you.</p> + +<p>This generates (basically) the following markup when the list of managers is +Kyle Brovlovski, Stan Marsh, Eric Cartman, and Kenny McCormick:</p> + +<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><tr></span> + <span class="nt"><th></span>Managed by<span class="nt"></th></span> + <span class="nt"><td></span> + <span class="nt"><select</span> <span class="na">wicket:id=</span><span class="s">"managedBy"</span> <span class="na">name=</span><span class="s">"managedBy"</span><span class="nt">></span> + <span class="nt"><option</span> <span class="na">selected=</span><span class="s">"selected"</span> <span class="na">value=</span><span class="s">""</span><span class="nt">></span>Choose one<span class="nt"></option></span> + <span class="nt"><option</span> <span class="na">value=</span><span class="s">"0"</span><span class="nt">></span>Kyle Brovlovski<span class="nt"></option></span> + <span class="nt"><option</span> <span class="na">value=</span><span class="s">"1"</span><span class="nt">></span>Stan Marsh<span class="nt"></option></span> + <span class="nt"><option</span> <span class="na">value=</span><span class="s">"2"</span><span class="nt">></span>Eric Cartman<span class="nt"></option></span> + <span class="nt"><option</span> <span class="na">value=</span><span class="s">"3"</span><span class="nt">></span>Kenny McCormick<span class="nt"></option></span> + <span class="nt"></select></span> + <span class="nt"></td></span> +<span class="nt"></tr></span></code></pre></div> + +<p>As you can see from this markup is that Wicket added the items of the +managers list and numbered the values of the options. These are the indices +of the items in the list. If the order of the list can change between +requests, <em>or</em> if the list itself can change, then please use an +<code>IChoiceRenderer</code>.</p> + +<h2 id="selecting-a-choice">Selecting a choice</h2> + +<p>Now if a user selects a value and submits the form, Wicket will assign the +manager to the employee (the <code>PropertyModel</code> takes care of that). The +following list shows what basically happens:</p> + +<ol> + <li>create new Employee, with <code>null</code> for its manager</li> + <li>create AssignManagerPage with the employee</li> + <li>render page, selected value is <code>"Choose one"</code></li> + <li>user selects âEric Cartmanâ and submits form</li> + <li>Wicket assigns manager âEric Cartmanâ to <code>managedBy</code> field of the employee</li> +</ol> + +<p>So there is no need for getting or setting the value from the drop down +component: Wicket binds directly to your domain objects if you use the +correct models.</p> + +<h2 id="selecting-a-default-choice">Selecting a default choice</h2> + +<p>If you want to select a default value for the manager, then all you need to +do is assign the default manager to the employee and Wicket will take care of +the rest:</p> + +<div class="highlight"><pre><code class="language-java" data-lang="java"><span class="c1">// some add new employee code</span> +<span class="n">Employee</span> <span class="n">manager</span> <span class="o">=</span> <span class="n">Employee</span><span class="o">.</span><span class="na">get</span><span class="o">(</span><span class="s">"Eric Cartman"</span><span class="o">);</span> <span class="c1">// gets a manager</span> +<span class="n">Employee</span> <span class="n">newEmployee</span> <span class="o">=</span> <span class="k">new</span> <span class="nf">Employee</span><span class="o">();</span> +<span class="n">newEmployee</span><span class="o">.</span><span class="na">setManagedBy</span><span class="o">(</span><span class="n">manager</span><span class="o">);</span> + +<span class="n">setResponsePage</span><span class="o">(</span><span class="k">new</span> <span class="nf">AssignManagerPage</span><span class="o">(</span><span class="n">newEmployee</span><span class="o">));</span></code></pre></div> + +<h2 id="summary">Summary</h2> + +<p>This concludes the (small) example of using a <code>DropDownChoice</code> component +correctly. The ideas behind Wicket are perfectly reflected in this component: +work with your domain objects, bind them to your components and get on with +the rest of your application.</p> + + </div> + <div id="clearer"></div> + <div id="footer"><span> +Copyright © 2015 — 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>
http://git-wip-us.apache.org/repos/asf/wicket-site/blob/8cc72bad/_site/learn/examples/guestbook.html ---------------------------------------------------------------------- diff --git a/_site/learn/examples/guestbook.html b/_site/learn/examples/guestbook.html new file mode 100644 index 0000000..fc918a6 --- /dev/null +++ b/_site/learn/examples/guestbook.html @@ -0,0 +1,460 @@ +<!DOCTYPE html> +<html> +<head> + <title>Apache Wicket - Guestbook</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.19.0">Wicket 6.19</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-M5">Download M5</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>Guestbook</h1> + <p>The GuestBook application allows users to enter comments that appear on a +page like a weblog. Drawing the list of comments is very easy with the Wicket +<code>ListView</code> component. This example also gives an impression of what form +handling is like.</p> + +<p><img src="guestbook.png" alt="Guestbook screenshot" /></p> + +<p>As with all examples, you have to put all files in the same package +directory. This means putting the markup files and the java files next to one +another. It is possible to alter this behavior, but that is beyond the scope +of this example.</p> + +<h2 id="commentjava">Comment.java</h2> + +<p>The Comment POJO model is very straightforward:</p> + +<div class="highlight"><pre><code class="language-java" data-lang="java"><span class="kn">package</span> <span class="n">org</span><span class="o">.</span><span class="na">apache</span><span class="o">.</span><span class="na">wicket</span><span class="o">.</span><span class="na">examples</span><span class="o">.</span><span class="na">guestbook</span><span class="o">;</span> + +<span class="kn">import</span> <span class="nn">java.util.Date</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.IClusterable</span><span class="o">;</span> + +<span class="kd">public</span> <span class="kd">class</span> <span class="nc">Comment</span> <span class="kd">implements</span> <span class="n">IClusterable</span> <span class="o">{</span> + <span class="kd">private</span> <span class="n">String</span> <span class="n">text</span><span class="o">;</span> + <span class="kd">private</span> <span class="n">Date</span> <span class="n">date</span> <span class="o">=</span> <span class="k">new</span> <span class="nf">Date</span><span class="o">();</span> + + <span class="kd">public</span> <span class="nf">Comment</span><span class="o">()</span> <span class="o">{</span> + <span class="o">}</span> + + <span class="kd">public</span> <span class="nf">Comment</span><span class="o">(</span><span class="kd">final</span> <span class="n">Comment</span> <span class="n">comment</span><span class="o">)</span> <span class="o">{</span> + <span class="k">this</span><span class="o">.</span><span class="na">text</span> <span class="o">=</span> <span class="n">comment</span><span class="o">.</span><span class="na">text</span><span class="o">;</span> + <span class="k">this</span><span class="o">.</span><span class="na">date</span> <span class="o">=</span> <span class="n">comment</span><span class="o">.</span><span class="na">date</span><span class="o">;</span> + <span class="o">}</span> + + <span class="kd">public</span> <span class="n">String</span> <span class="nf">getText</span><span class="o">()</span> <span class="o">{</span> + <span class="k">return</span> <span class="n">text</span><span class="o">;</span> + <span class="o">}</span> + + <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setText</span><span class="o">(</span><span class="n">String</span> <span class="n">text</span><span class="o">)</span> <span class="o">{</span> + <span class="k">this</span><span class="o">.</span><span class="na">text</span> <span class="o">=</span> <span class="n">text</span><span class="o">;</span> + <span class="o">}</span> + + <span class="kd">public</span> <span class="n">Date</span> <span class="nf">getDate</span><span class="o">()</span> <span class="o">{</span> + <span class="k">return</span> <span class="n">date</span><span class="o">;</span> + <span class="o">}</span> + + <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setDate</span><span class="o">(</span><span class="n">Date</span> <span class="n">date</span><span class="o">)</span> <span class="o">{</span> + <span class="k">this</span><span class="o">.</span><span class="na">date</span> <span class="o">=</span> <span class="n">date</span><span class="o">;</span> + <span class="o">}</span> + + <span class="kd">public</span> <span class="n">String</span> <span class="nf">toString</span><span class="o">()</span> <span class="o">{</span> + <span class="k">return</span> <span class="s">"[Comment date = "</span> <span class="o">+</span> <span class="n">date</span> <span class="o">+</span> <span class="s">", text = "</span> <span class="o">+</span> <span class="n">text</span> <span class="o">+</span> <span class="s">"]"</span><span class="o">;</span> + <span class="o">}</span> +<span class="o">}</span></code></pre></div> + +<h2 id="guestbookjava">GuestBook.java</h2> + +<p>In the file <code>GuestBook.java</code> we have put the Java component code for the +guestbook page. This is the homepage for the guestbook application. The page +consists of a form for entering new items to the guestbook and a list of +repeating markup for showing the guestbook entries.</p> + +<p>The <code>GuestBook</code> constructor adds a <code>CommentForm</code> and a <code>ListView</code> of +the comments. Notice how the model is passed in as the second argument to the +<code>ListView</code> constructor.</p> + +<p>Then as the view renders, the <code>populateItem</code> method is called passing in a +<code>ListItem</code> container for the current row in the list.</p> + +<p>The implementation below obtains the <code>Comment</code> POJO from the list item and +adds label components for the date and text of the <code>Comment</code>. This is all +accomplished in just a few lines of code.</p> + +<div class="highlight"><pre><code class="language-java" data-lang="java"><span class="kn">package</span> <span class="n">org</span><span class="o">.</span><span class="na">apache</span><span class="o">.</span><span class="na">wicket</span><span class="o">.</span><span class="na">examples</span><span class="o">.</span><span class="na">guestbook</span><span class="o">;</span> + +<span class="kn">import</span> <span class="nn">java.util.ArrayList</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">java.util.Collections</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">java.util.Date</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">java.util.List</span><span class="o">;</span> + +<span class="kn">import</span> <span class="nn">org.apache.commons.lang.StringUtils</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.examples.WicketExamplePage</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.markup.html.basic.Label</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.markup.html.basic.MultiLineLabel</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.markup.html.form.Form</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.markup.html.form.TextArea</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.markup.html.form.TextField</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.markup.html.list.ListItem</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.markup.html.list.PropertyListView</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.model.CompoundPropertyModel</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.util.value.ValueMap</span><span class="o">;</span> + + +<span class="kd">public</span> <span class="kd">final</span> <span class="kd">class</span> <span class="nc">GuestBook</span> <span class="kd">extends</span> <span class="n">WicketExamplePage</span> <span class="o">{</span> + <span class="cm">/** A global list of all comments from all users across all sessions */</span> + <span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">List</span><span class="o"><</span><span class="n">Comment</span><span class="o">></span> <span class="n">commentList</span> <span class="o">=</span> <span class="n">Collections</span><span class="o">.</span><span class="na">synchronizedList</span><span class="o">(</span><span class="k">new</span> <span class="n">ArrayList</span><span class="o"><</span><span class="n">Comment</span><span class="o">>());</span> + + <span class="cm">/**</span> +<span class="cm"> * Constructor that is invoked when page is invoked without a session.</span> +<span class="cm"> */</span> + <span class="kd">public</span> <span class="nf">GuestBook</span><span class="o">()</span> <span class="o">{</span> + <span class="c1">// Add comment form</span> + <span class="n">add</span><span class="o">(</span><span class="k">new</span> <span class="nf">CommentForm</span><span class="o">(</span><span class="s">"commentForm"</span><span class="o">));</span> + + <span class="c1">// Add commentListView of existing comments</span> + <span class="n">add</span><span class="o">(</span><span class="k">new</span> <span class="n">PropertyListView</span><span class="o"><</span><span class="n">Comment</span><span class="o">>(</span><span class="s">"comments"</span><span class="o">,</span> <span class="n">commentList</span><span class="o">)</span> <span class="o">{</span> + <span class="nd">@Override</span> + <span class="kd">public</span> <span class="kt">void</span> <span class="nf">populateItem</span><span class="o">(</span><span class="kd">final</span> <span class="n">ListItem</span><span class="o"><</span><span class="n">Comment</span><span class="o">></span> <span class="n">listItem</span><span class="o">)</span> <span class="o">{</span> + <span class="n">listItem</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="k">new</span> <span class="nf">Label</span><span class="o">(</span><span class="s">"date"</span><span class="o">));</span> + <span class="n">listItem</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="k">new</span> <span class="nf">MultiLineLabel</span><span class="o">(</span><span class="s">"text"</span><span class="o">));</span> + <span class="o">}</span> + <span class="o">}).</span><span class="na">setVersioned</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span> + <span class="o">}</span> + + <span class="cm">/**</span> +<span class="cm"> * A form that allows a user to add a comment.</span> +<span class="cm"> */</span> + <span class="kd">public</span> <span class="kd">final</span> <span class="kd">class</span> <span class="nc">CommentForm</span> <span class="kd">extends</span> <span class="n">Form</span><span class="o"><</span><span class="n">ValueMap</span><span class="o">></span> <span class="o">{</span> + <span class="kd">public</span> <span class="nf">CommentForm</span><span class="o">(</span><span class="kd">final</span> <span class="n">String</span> <span class="n">id</span><span class="o">)</span> <span class="o">{</span> + <span class="c1">// Construct form with no validation listener</span> + <span class="kd">super</span><span class="o">(</span><span class="n">id</span><span class="o">,</span> <span class="k">new</span> <span class="n">CompoundPropertyModel</span><span class="o"><</span><span class="n">ValueMap</span><span class="o">>(</span><span class="k">new</span> <span class="nf">ValueMap</span><span class="o">()));</span> + + <span class="c1">// this is just to make the unit test happy</span> + <span class="n">setMarkupId</span><span class="o">(</span><span class="s">"commentForm"</span><span class="o">);</span> + + <span class="c1">// Add text entry widget</span> + <span class="n">add</span><span class="o">(</span><span class="k">new</span> <span class="n">TextArea</span><span class="o"><</span><span class="n">String</span><span class="o">>(</span><span class="s">"text"</span><span class="o">).</span><span class="na">setType</span><span class="o">(</span><span class="n">String</span><span class="o">.</span><span class="na">class</span><span class="o">));</span> + + <span class="c1">// Add simple automated spam prevention measure.</span> + <span class="n">add</span><span class="o">(</span><span class="k">new</span> <span class="n">TextField</span><span class="o"><</span><span class="n">String</span><span class="o">>(</span><span class="s">"comment"</span><span class="o">).</span><span class="na">setType</span><span class="o">(</span><span class="n">String</span><span class="o">.</span><span class="na">class</span><span class="o">));</span> + <span class="o">}</span> + + <span class="cm">/**</span> +<span class="cm"> * Show the resulting valid edit</span> +<span class="cm"> */</span> + <span class="nd">@Override</span> + <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">onSubmit</span><span class="o">()</span> <span class="o">{</span> + <span class="n">ValueMap</span> <span class="n">values</span> <span class="o">=</span> <span class="n">getModelObject</span><span class="o">();</span> + + <span class="c1">// check if the honey pot is filled</span> + <span class="k">if</span> <span class="o">(</span><span class="n">StringUtils</span><span class="o">.</span><span class="na">isNotBlank</span><span class="o">((</span><span class="n">String</span><span class="o">)</span><span class="n">values</span><span class="o">.</span><span class="na">get</span><span class="o">(</span><span class="s">"comment"</span><span class="o">)))</span> <span class="o">{</span> + <span class="n">error</span><span class="o">(</span><span class="s">"Caught a spammer!!!"</span><span class="o">);</span> + <span class="k">return</span><span class="o">;</span> + <span class="o">}</span> + <span class="c1">// Construct a copy of the edited comment</span> + <span class="n">Comment</span> <span class="n">comment</span> <span class="o">=</span> <span class="k">new</span> <span class="nf">Comment</span><span class="o">();</span> + + <span class="c1">// Set date of comment to add</span> + <span class="n">comment</span><span class="o">.</span><span class="na">setDate</span><span class="o">(</span><span class="k">new</span> <span class="nf">Date</span><span class="o">());</span> + <span class="n">comment</span><span class="o">.</span><span class="na">setText</span><span class="o">((</span><span class="n">String</span><span class="o">)</span><span class="n">values</span><span class="o">.</span><span class="na">get</span><span class="o">(</span><span class="s">"text"</span><span class="o">));</span> + <span class="n">commentList</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">comment</span><span class="o">);</span> + + <span class="c1">// Clear out the text component</span> + <span class="n">values</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"text"</span><span class="o">,</span> <span class="s">""</span><span class="o">);</span> + <span class="o">}</span> + <span class="o">}</span> + + <span class="cm">/**</span> +<span class="cm"> * Clears the comments.</span> +<span class="cm"> */</span> + <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">clear</span><span class="o">()</span> <span class="o">{</span> + <span class="n">commentList</span><span class="o">.</span><span class="na">clear</span><span class="o">();</span> + <span class="o">}</span> +<span class="o">}</span></code></pre></div> + +<p>When the <code>CommentForm</code> is submitted, the <code>onSubmit()</code> method is called. +Notice that nothing gets the value of the <code>TextArea</code> that was added in the +<code>CommentForm</code> constructor. This is because the comment is the model and the +third parameter to the <code>TextArea</code> constructor specified the property of the +model to update. So all <code>onSubmit()</code> has to do is create a new comment from +the model that was updated and add it to the comment list. When the page +redraws, the new list will be rendered.</p> + +<p>We use a synchronized list as our shared static model used by <code>commentListView</code> +(<code>commentList</code>) to ensure that it is only updated by one thread at a time. +Remember, this is a multi-user application with a shared model!</p> + +<p>Finally, you may notice the call to <code>commentListView.modelChanged()</code>. This +informs the list view that its model has been modified. In more advanced +usage scenarios, this would allow Wicket to expire stale pages accessed with +the browserâs back button.</p> + +<h2 id="guestbookhtml">GuestBook.html</h2> + +<p>In the HTML below, notice the way that the <code>TextArea</code> component is being +nested inside the <code>CommentForm</code>. Wicket is able to keep everything straight +because the Java <code>Component.add()</code> calls have to result in the same nesting +structure as the HTML.</p> + +<p>Finally, notice the <code><wicket:remove></code> block. This is simply markup that is +there for previewing purposes only. When the page renders, it is stripped +out.</p> + +<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><html</span> <span class="na">xmlns:wicket=</span><span class="s">"http://wicket.apache.org/"</span><span class="nt">></span> +<span class="nt"><head></span> + <span class="nt"><title></span>Wicket Examples - guestbook<span class="nt"></title></span> + <span class="nt"><link</span> <span class="na">rel=</span><span class="s">"stylesheet"</span> <span class="na">type=</span><span class="s">"text/css"</span> <span class="na">href=</span><span class="s">"style.css"</span><span class="nt">/></span> +<span class="nt"></head></span> +<span class="nt"><body></span> + <span class="nt"><span</span> <span class="na">wicket:id=</span><span class="s">"mainNavigation"</span><span class="nt">/></span> + + <span class="nt"><form</span> <span class="na">wicket:id=</span><span class="s">"commentForm"</span><span class="nt">></span> + Add your comment here: + <span class="nt"><p></span> + <span class="nt"><textarea</span> <span class="na">wicket:id=</span><span class="s">"text"</span><span class="nt">></span>This is a comment<span class="nt"></textarea></span> + <span class="nt"><input</span> <span class="na">type=</span><span class="s">"text"</span> <span class="na">wicket:id=</span><span class="s">"comment"</span> <span class="na">class=</span><span class="s">"nospam"</span> <span class="na">onfocus=</span><span class="s">"getElementById('formsubmit').focus();"</span><span class="nt">/></span> + <span class="nt"><p></span> + <span class="nt"><input</span> <span class="na">type=</span><span class="s">"submit"</span> <span class="na">value=</span><span class="s">"Submit"</span> <span class="na">id=</span><span class="s">"formsubmit"</span><span class="nt">/></span> + <span class="nt"></form></span> + <span class="nt"><p/></span> + <span class="nt"><span</span> <span class="na">wicket:id=</span><span class="s">"comments"</span><span class="nt">></span> + <span class="nt"><p></span> + <span class="nt"><span</span> <span class="na">wicket:id=</span><span class="s">"date"</span><span class="nt">></span>1/1/2004<span class="nt"></span><br></span> + <span class="nt"><span</span> <span class="na">wicket:id=</span><span class="s">"text"</span><span class="nt">></span>Comment text goes here.<span class="nt"></span></span> + <span class="nt"></p></span> + <span class="nt"></span></span> + <span class="nt"><wicket:remove></span> + <span class="nt"><p></span> + 1/2/2004<span class="nt"><br/></span> + More comment text here. + <span class="nt"></p></span> + <span class="nt"></wicket:remove></span> +<span class="nt"></body></span> +<span class="nt"></html></span></code></pre></div> + +<h2 id="guestbookapplicationjava">GuestBookApplication.java</h2> + +<p>For completeness, weâve included the <code>GuestBookApplication</code> class, and as a +final treat the modifications to the <code>web.xml</code> file.</p> + +<div class="highlight"><pre><code class="language-java" data-lang="java"><span class="kn">package</span> <span class="n">org</span><span class="o">.</span><span class="na">apache</span><span class="o">.</span><span class="na">wicket</span><span class="o">.</span><span class="na">examples</span><span class="o">.</span><span class="na">guestbook</span><span class="o">;</span> + +<span class="kn">import</span> <span class="nn">org.apache.wicket.Page</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.examples.WicketExampleApplication</span><span class="o">;</span> + +<span class="kd">public</span> <span class="kd">class</span> <span class="nc">GuestBookApplication</span> <span class="kd">extends</span> <span class="n">WicketExampleApplication</span> <span class="o">{</span> + <span class="kd">public</span> <span class="nf">GuestBookApplication</span><span class="o">()</span> <span class="o">{</span> + <span class="o">}</span> + + <span class="nd">@Override</span> + <span class="kd">public</span> <span class="n">Class</span><span class="o"><</span> <span class="o">?</span> <span class="kd">extends</span> <span class="n">Page</span><span class="o">></span> <span class="nf">getHomePage</span><span class="o">()</span> <span class="o">{</span> + <span class="k">return</span> <span class="n">GuestBook</span><span class="o">.</span><span class="na">class</span><span class="o">;</span> + <span class="o">}</span> +<span class="o">}</span></code></pre></div> + +<h2 id="webxml">web.xml</h2> + +<p>Add the following two sections (servlet and servlet-mapping) to your web.xml +file for running this application.</p> + +<div class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="nt"><filter></span> + <span class="nt"><filter-name></span>GuestBookApplication<span class="nt"></filter-name></span> + <span class="nt"><filter-class></span>org.apache.wicket.protocol.http.WicketFilter<span class="nt"></filter-class></span> + <span class="nt"><init-param></span> + <span class="nt"><param-name></span>applicationClassName<span class="nt"></param-name></span> + <span class="nt"><param-value></span>org.apache.wicket.examples.guestbook.GuestBookApplication<span class="nt"></param-value></span> + <span class="nt"></init-param></span> +<span class="nt"></filter></span></code></pre></div> + + + </div> + <div id="clearer"></div> + <div id="footer"><span> +Copyright © 2015 — 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> http://git-wip-us.apache.org/repos/asf/wicket-site/blob/8cc72bad/_site/learn/examples/guestbook.png ---------------------------------------------------------------------- diff --git a/_site/learn/examples/guestbook.png b/_site/learn/examples/guestbook.png new file mode 100644 index 0000000..76669da Binary files /dev/null and b/_site/learn/examples/guestbook.png differ http://git-wip-us.apache.org/repos/asf/wicket-site/blob/8cc72bad/_site/learn/examples/helloworld.html ---------------------------------------------------------------------- diff --git a/_site/learn/examples/helloworld.html b/_site/learn/examples/helloworld.html new file mode 100644 index 0000000..e27d3c4 --- /dev/null +++ b/_site/learn/examples/helloworld.html @@ -0,0 +1,343 @@ +<!DOCTYPE html> +<html> +<head> + <title>Apache Wicket - Hello World!</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.19.0">Wicket 6.19</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-M5">Download M5</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>Hello World!</h1> + <p>HelloWorld demonstrates the basic structure of a web application in Wicket. A +Label component is used to display a message on the home page for the +application.</p> + +<p>In all the Wicket examples, you have to put all files in the same package +directory. This means putting the markup files and the java files next to one +another. It is possible to alter this behavior, but that is beyond the scope +of this example. The only exception is the obligatory web.xml file which +should reside in the WEB-INF/ directory of your web application root folder.</p> + +<p>If you wish to start building this example, you may want to take a look at the +Wicket Quickstart project, which provides a quick way of getting up and +running without having to figure things out yourself. The Quickstart project +contains the necessary build files (Ant and Maven), libraries, minimal set of +Java and markup files and an embedded Jetty server to run your application +without having to go through the whole build-deploy cycle.</p> + +<h3 id="helloworldapplicationjava">HelloWorldApplication.java</h3> + +<p>Each Wicket application is defined by an Application object. This object +defines what the home page is, and allows for some configuration.</p> + +<div class="highlight"><pre><code class="language-java" data-lang="java"><span class="kn">import</span> <span class="nn">org.apache.wicket.protocol.http.WebApplication</span><span class="o">;</span> + +<span class="kd">public</span> <span class="kd">class</span> <span class="nc">HelloWorldApplication</span> <span class="kd">extends</span> <span class="n">WebApplication</span> <span class="o">{</span> + <span class="kd">public</span> <span class="nf">HelloWorldApplication</span><span class="o">()</span> <span class="o">{</span> + <span class="o">}</span> + + <span class="cm">/**</span> +<span class="cm"> * @see org.apache.wicket.Application#getHomePage()</span> +<span class="cm"> */</span> + <span class="nd">@Override</span> + <span class="kd">public</span> <span class="n">Class</span> <span class="nf">getHomePage</span><span class="o">()</span> <span class="o">{</span> + <span class="k">return</span> <span class="n">HelloWorld</span><span class="o">.</span><span class="na">class</span><span class="o">;</span> + <span class="o">}</span> +<span class="o">}</span></code></pre></div> + +<p>Here you can see that we define <code>wicket.examples.helloworld.HelloWorld</code> to be +our home page. When the base URL of our application is requested, the markup +rendered by the HelloWorld page is returned.</p> + +<h3 id="helloworldjava">HelloWorld.java</h3> + +<div class="highlight"><pre><code class="language-java" data-lang="java"><span class="kn">import</span> <span class="nn">org.apache.wicket.markup.html.WebPage</span><span class="o">;</span> +<span class="kn">import</span> <span class="nn">org.apache.wicket.markup.html.basic.Label</span><span class="o">;</span> + +<span class="kd">public</span> <span class="kd">class</span> <span class="nc">HelloWorld</span> <span class="kd">extends</span> <span class="n">WebPage</span> <span class="o">{</span> + <span class="kd">public</span> <span class="nf">HelloWorld</span><span class="o">()</span> <span class="o">{</span> + <span class="n">add</span><span class="o">(</span><span class="k">new</span> <span class="nf">Label</span><span class="o">(</span><span class="s">"message"</span><span class="o">,</span> <span class="s">"Hello World!"</span><span class="o">));</span> + <span class="o">}</span> +<span class="o">}</span></code></pre></div> + +<p>The Label is constructed using two parameters:</p> + +<ol> + <li> + <p>âmessageâ</p> + </li> + <li> + <p>âHello World!â</p> + </li> +</ol> + +<p>The first parameter is the component identifier, which Wicket uses to identify +the <code>Label</code> component in your HTML markup. The second parameter is the message +which the <code>Label</code> should render.</p> + +<h3 id="helloworldhtml">HelloWorld.html</h3> + +<p>The HTML file that defines our Hello World functionality is as follows:</p> + +<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><html></span> +<span class="nt"><body></span> + <span class="nt"><span</span> <span class="na">wicket:id=</span><span class="s">"message"</span><span class="nt">></span>Message goes here<span class="nt"></span></span> +<span class="nt"></body></span> +<span class="nt"></html></span></code></pre></div> + +<p>In this file, you see two elements that need some attention:</p> + +<ul> + <li> + <p>the component declaration <code><span wicket:id="message"></code></p> + </li> + <li> + <p>the text <code>Message goes here</code></p> + </li> +</ul> + +<p>The component declaration consists of the Wicket identifier <code>wicket:id</code> and the +component identifier <code>message</code>. The component identifier should be the same as +the name of the component you defined in your <code>WebPage</code>. The text between +the <code><span></code> tags is removed when the component renders its message. The final +content of the component is determined by your Java code.</p> + +<h3 id="webxml">web.xml</h3> + +<p>In order to deploy our HelloWorld program, we need to make our application +known to the application server by means of the web.xml file.</p> + +<div class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="cp"><?xml version="1.0" encoding="UTF-8"?></span> +<span class="cp"><!DOCTYPE web-app</span> +<span class="cp"> PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"</span> +<span class="cp"> "http://java.sun.com/dtd/web-app_2_3.dtd"></span> + +<span class="nt"><web-app></span> + <span class="nt"><display-name></span>Wicket Examples<span class="nt"></display-name></span> + <span class="nt"><filter></span> + <span class="nt"><filter-name></span>HelloWorldApplication<span class="nt"></filter-name></span> + <span class="nt"><filter-class></span>org.apache.wicket.protocol.http.WicketFilter<span class="nt"></filter-class></span> + <span class="nt"><init-param></span> + <span class="nt"><param-name></span>applicationClassName<span class="nt"></param-name></span> + <span class="nt"><param-value></span>org.apache.wicket.examples.helloworld.HelloWorldApplication<span class="nt"></param-value></span> + <span class="nt"></init-param></span> + <span class="nt"></filter></span> + <span class="nt"><filter-mapping></span> + <span class="nt"><filter-name></span>HelloWorldApplication<span class="nt"></filter-name></span> + <span class="nt"><url-pattern></span>/*<span class="nt"></url-pattern></span> + <span class="nt"></filter-mapping></span> +<span class="nt"></web-app></span></code></pre></div> + +<p>In this definition you see the Wicket filter defined, which handles all +requests. In order to let Wicket know which application is available, only the +applicationClassName filter parameter is needed.</p> + +<p>Also, notice the url-mapping to /*. The Wicket filter will only process +requests that are Wicket requests. If a request is not Wicket related, the +filter will pass the request on to the chain. This ensures that (static) +resources outside the realm of the Wicket application, such as style sheets, +JavaScript files, images and so forth will be served by the container.</p> + +<h2 id="ready-to-deploy">Ready to deploy</h2> + +<p>Thatâs it. No more configuration necessary! All you need to do now is to +deploy the web application into your favorite application server. Point your +browser to the url: <code>http://<servername>/<warfilename>/</code>, substituting +servername and warfilename to the appropriate values, such as +http://localhost:8080/helloworld/.</p> + +<p>As you can see: no superfluous XML configuration files are needed to enable a +Wicket application. Only the markup (HTML) files, the Java class files and the +required web.xml were needed to create this application.</p> + + </div> + <div id="clearer"></div> + <div id="footer"><span> +Copyright © 2015 — 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> http://git-wip-us.apache.org/repos/asf/wicket-site/blob/8cc72bad/_site/learn/examples/index.html ---------------------------------------------------------------------- diff --git a/_site/learn/examples/index.html b/_site/learn/examples/index.html new file mode 100644 index 0000000..53891d1 --- /dev/null +++ b/_site/learn/examples/index.html @@ -0,0 +1,226 @@ +<!DOCTYPE html> +<html> +<head> + <title>Apache Wicket - A Quick Tour of Wicket</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.19.0">Wicket 6.19</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-M5">Download M5</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>A Quick Tour of Wicket</h1> + <p>Nothing says more about a development technology than a few simple examples. +After all, how hard should it be to do something easy? The examples below +should speak for themselves in demonstrating how easy it is to get things done +in Wicket when compared to other frameworks. You will discover that Wicketâs +component-oriented structure and its âlow touchâ approach to HTML is quite +inviting.</p> + +<p>You can see these examples and many more in <a href="http://www.wicket-library.com/wicket-examples-6.0.x">live +action</a> without having to install anything.</p> + +<ul> + <li><a href="helloworld.html">Hello World!</a> - Everybodyâs favorite example</li> + <li><a href="navomatic.html">Navomatic</a> - Automatic navigation using Borders and Links</li> + <li><a href="guestbook.html">GuestBook</a> - A tiny blogger demonstrating ListViews and +Forms</li> + <li><a href="dropdownchoice.html">Using DropDownChoice</a> - A short example explaining the +DropDownChoice component</li> + <li><a href="markupinheritance.html">Markup Inheritance</a> - A short example explaining +markup inheritance</li> + <li><a href="ajaxcounter.html">Ajax Counter</a> - A short example explaining Wicketâs Ajax +features building a counter.</li> + <li><a href="usingfragments.html">Using Fragments</a> - A short example explaining Wicketâs +fragments feature. Fragments are a type of inline panels.</li> +</ul> + + </div> + <div id="clearer"></div> + <div id="footer"><span> +Copyright © 2015 — 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>
