<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Wicket by Example</title>
	
	<link>http://wicketbyexample.com</link>
	<description>Examples of using Apache Wicket for Java</description>
	<lastBuildDate>Fri, 12 Feb 2010 18:36:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/WicketByExample" /><feedburner:info uri="wicketbyexample" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Apache Wicket Clustering With Multiple Options</title>
		<link>http://wicketbyexample.com/apache-wicket-clustering-with-multiple-options/</link>
		<comments>http://wicketbyexample.com/apache-wicket-clustering-with-multiple-options/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 05:23:35 +0000</pubDate>
		<dc:creator>kinabalu</dc:creator>
				<category><![CDATA[Example]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[hazelcast]]></category>
		<category><![CDATA[ipagestore]]></category>
		<category><![CDATA[pagemap]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=215</guid>
		<description><![CDATA[We&#8217;ve been seeing more and more implementations of IPageStore out in the wild for Apache Wicket.  The interface basically decides how Wicket will store the Pagemap for your application.  The default that ships with Wicket uses DiskPageStore which is an implementation that stores the serialized pages grouped in a single file per pagemap. [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>We&#8217;ve been seeing more and more implementations of <a href="http://wicketbyexample.com/api/wicket/1.4.5/org/apache/wicket/protocol/http/SecondLevelCacheSessionStore.IPageStore.html" target="_blank">IPageStore</a> out in the wild for <a href="http://wicket.apache.org/" target="_blank">Apache Wicket</a>.  The interface basically decides how Wicket will store the <a href="http://cwiki.apache.org/WICKET/page-maps.html" target="_blank">Pagemap</a> for your application.  The default that ships with Wicket uses <a href="http://wicketbyexample.com/api/wicket/1.4.6/org/apache/wicket/protocol/http/pagestore/DiskPageStore.html" target="_blank">DiskPageStore</a> which is an implementation that stores the serialized pages grouped in a single file per pagemap. After reading a wonderful blog post on <a href="http://letsgetdugg.com" target="_blank">Letsgetdugg</a> a few days ago: <a href="http://letsgetdugg.com/2010/02/07/clustering-wicket-for-fun-and-profit/" target="_blank">Clustering Wicket for fun and profit!</a>, I decided to take a look at writing an implementation using <a href="http://hazelcast.com" target="_blank">Hazelcast</a> &#8211; an &#8220;open source clustering and highly scalable data distribution platform&#8221;.<br />
<span id="more-215"></span><br />
The implementation below borrows heavily from <a href="http://fabulously40.com/fabulously/victori" target="_blank">Victor</a>.  It basically creates a HazelcastInstance in the constructor and then overrides all the methods necessary from <a href="http://wicketbyexample.com/api/wicket/1.4.5/org/apache/wicket/protocol/http/pagestore/AbstractPageStore.html" target="_blank">AbstractPageStore</a>.  Here&#8217;s some quick code to put in your app&#8217;s Application implementation that will use this new IPageStore:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code3'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2153"><td class="code" id="p215code3"><pre class="java" style="font-family:monospace;">    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> ISessionStore newSessionStore<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> SecondLevelCacheSessionStore<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>,
                <span style="color: #000000; font-weight: bold;">new</span> HazelcastPageStore<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;default&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And here&#8217;s the code for HazelcastPageStore:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p215code4'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2154"><td class="code" id="p215code4"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HazelcastPageStore <span style="color: #000000; font-weight: bold;">extends</span> AbstractPageStore 
                                      <span style="color: #000000; font-weight: bold;">implements</span> SecondLevelCacheSessionStore.<span style="color: #006633;">IClusteredPageStore</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Logger logger <span style="color: #339933;">=</span> LoggerFactory.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>HazelcastPageStore.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> mapName<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> HazelcastInstance client<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> HazelcastPageStore<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> mapName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#40;</span>mapName, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> HazelcastPageStore<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> mapName, Config config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mapName</span> <span style="color: #339933;">=</span> mapName<span style="color: #339933;">;</span>
        client <span style="color: #339933;">=</span> Hazelcast.<span style="color: #006633;">newHazelcastInstance</span><span style="color: #009900;">&#40;</span>config<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getKey<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sessId, <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> pageMapName, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> pageId, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> pageVersion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> getKey<span style="color: #009900;">&#40;</span>sessId, pageMapName, pageId, pageVersion, <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getKey<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sessId, <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> pageMapName, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> pageId, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> pageVersion, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> ajaxVersion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #339933;">=</span> sessId <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> pageMapName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> pageId <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> pageVersion <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> ajaxVersion<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>logger.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GetKey: &quot;</span> <span style="color: #339933;">+</span> key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> key<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> storeKey<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sessionId, <span style="color: #000000; font-weight: bold;">final</span> Page page<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #339933;">=</span> sessionId <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> page.<span style="color: #006633;">getPageMapName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> page.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> page.<span style="color: #006633;">getCurrentVersionNumber</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>page.<span style="color: #006633;">getAjaxVersionNumber</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>logger.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;StoreKey: &quot;</span> <span style="color: #339933;">+</span> key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> key<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> containsPage<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sessionId, <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> pageMapName, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> pageId, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> pageVersion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> client.<span style="color: #006633;">getMap</span><span style="color: #009900;">&#40;</span>mapName<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>getKey<span style="color: #009900;">&#40;</span>sessionId, pageMapName, pageId, pageVersion<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> destroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        client.<span style="color: #006633;">shutdown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> Page getPage<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sessionId, <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> pagemap, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> id, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> versionNumber, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> ajaxVersionNumber<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        IMap<span style="color: #339933;">&lt;</span>String, Page<span style="color: #339933;">&gt;</span> map <span style="color: #339933;">=</span> client.<span style="color: #006633;">getMap</span><span style="color: #009900;">&#40;</span>mapName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> map.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>getKey<span style="color: #009900;">&#40;</span>sessionId, pagemap, id, versionNumber, ajaxVersionNumber<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> pageAccessed<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sessionId, <span style="color: #000000; font-weight: bold;">final</span> Page page<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> removePage<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sessionId, <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> pagemap, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #339933;">=</span> getKey<span style="color: #009900;">&#40;</span>sessionId, pagemap, id, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        key <span style="color: #339933;">=</span> key.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, key.<span style="color: #006633;">lastIndexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        IMap<span style="color: #339933;">&lt;</span>String, Page<span style="color: #339933;">&gt;</span> map <span style="color: #339933;">=</span> Hazelcast.<span style="color: #006633;">getMap</span><span style="color: #009900;">&#40;</span>mapName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> k <span style="color: #339933;">:</span> map.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>k.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                map.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>k<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> storePage<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sessionId, <span style="color: #000000; font-weight: bold;">final</span> Page page<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        IMap<span style="color: #339933;">&lt;</span>String, Page<span style="color: #339933;">&gt;</span> map <span style="color: #339933;">=</span> client.<span style="color: #006633;">getMap</span><span style="color: #009900;">&#40;</span>mapName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        map.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>storeKey<span style="color: #009900;">&#40;</span>sessionId, page<span style="color: #009900;">&#41;</span>, page<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> unbind<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sessionId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        IMap<span style="color: #339933;">&lt;</span>String, Page<span style="color: #339933;">&gt;</span> map <span style="color: #339933;">=</span> client.<span style="color: #006633;">getMap</span><span style="color: #009900;">&#40;</span>mapName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #339933;">:</span> map.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span>sessionId<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                map.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Several other IPageStore implementations available:</p>
<ul>
<li><a href="http://letsgetdugg.com/2010/02/07/clustering-wicket-for-fun-and-profit/" target="_blank">Letsgetdugg &#8211; memcached implementation</a></li>
<li><a href="http://www.mail-archive.com/users@wicket.apache.org/msg46421.html" target="_blank">Google App Engine memcached implementation</a></li>
</ul>
<p>Let us know if you find any others out in the wild so we can add them here.</p>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/apache-wicket-clustering-with-multiple-options/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wicket Ajax Confirmation Modal window</title>
		<link>http://wicketbyexample.com/wicket-ajax-confirmation-modal-window/</link>
		<comments>http://wicketbyexample.com/wicket-ajax-confirmation-modal-window/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 18:24:56 +0000</pubDate>
		<dc:creator>kinabalu</dc:creator>
				<category><![CDATA[Example]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[apache wicket]]></category>
		<category><![CDATA[modal]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=207</guid>
		<description><![CDATA[(Editor’s note: Tomasz Dziurko contributed this column from Code Hard Go Pro.)
While developing web application with Wicket I sometimes need to check whether the user really, really does want to do something, for example to delete an entity from the database. The first and easiest choice that comes to my mind is to use JavaScript [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><em>(Editor’s note: Tomasz Dziurko contributed this column from <a href="http://codehardgopro.blogspot.com/2010/02/wicket-ajax-modal-are-you-sure-window.html" target="_blank">Code Hard Go Pro</a>.)</em></p>
<p>While developing web application with Wicket I sometimes need to check whether the user really, really does want to do something, for example to delete an entity from the database. The first and easiest choice that comes to my mind is to use JavaScript window.<br />
<span id="more-207"></span><br />
So we have HomePage.html:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p207code13'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20713"><td class="code" id="p207code13"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html
    PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns:wicket=&quot;http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd&quot; &gt;
    &lt;head&gt;  
        &lt;title&gt;Wicket Ajax 'Are you sure?' Modal Window&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div align=&quot;center&quot;&gt;
            &lt;strong&gt;Wicket Ajax 'Are you sure?' Modal Window&lt;/strong&gt;
            &lt;form action=&quot;&quot; wicket:id=&quot;formWithJavaScript&quot;&gt;
                &lt;input type=&quot;submit&quot; wicket:id=&quot;buttonWithJavaScript&quot; value=&quot;Action!&quot;/&gt;
            &lt;/form&gt;
        &lt;/div&gt;        
    &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>and corresponding Java class:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p207code14'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20714"><td class="code" id="p207code14"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">pl.tdziurko.ajaxmodalwindowapp</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// imports omitted</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Author: Tomasz Dziurko
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HomePage <span style="color: #000000; font-weight: bold;">extends</span> WebPage <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> HomePage<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> PageParameters parameters<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        Form formWithJavaScript <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;formWithJavaScript&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a> buttonWithJavaScript <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;buttonWithJavaScript&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onSubmit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Doing my job&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        buttonWithJavaScript.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SimpleAttributeModifier<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">&quot;onclick&quot;</span>, <span style="color: #0000ff;">&quot;if(!confirm('Do you really want to perform this action?')) return false;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        formWithJavaScript.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>buttonWithJavaScript<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        add<span style="color: #009900;">&#40;</span>formWithJavaScript<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Finally, we can see how it looks:</p>
<p><img src="http://wicketbyexample.com/wp-content/uploads/2010/02/javaScriptWindow.PNG.png" alt="" title="javaScriptWindow.PNG" width="400" height="320" class="alignnone size-full wp-image-209" /></p>
<p>It solves our problem but in the era of Web2.0, rounded corners and shiny looks it isn&#8217;t enough. Why can&#8217;t we use ajax modal window to ask user for confirmation? It would make our application look good and our css magician could make it look even better.</p>
<p>So let&#8217;s try with creating reusable &#8216;Are you sure?&#8217; ajax modal window with Wicket.</p>
<p>At the beginning we must prepare panel which will be displayed in our modal window. Let&#8217;s name it YesNoPanel.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p207code15'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20715"><td class="code" id="p207code15"><pre class="html" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE html
    PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns:wicket&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;/&gt;
        &lt;title&gt;&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;wicket:panel&gt;
            &lt;form wicket:id=&quot;yesNoForm&quot; action=&quot;&quot;&gt;
                &lt;span wicket:id=&quot;message&quot;&gt;Are you sure?&lt;/span&gt;
                &lt;table style=&quot;width: 65%;&quot; align=&quot;center&quot;&gt;
                    &lt;tr&gt;
                        &lt;td align=&quot;left&quot;&gt;
                            &lt;input type=&quot;submit&quot; wicket:id=&quot;noButton&quot; value=&quot;No&quot; /&gt;
                        &lt;/td&gt;
                        &lt;td align=&quot;right&quot;&gt;
                            &lt;input type=&quot;submit&quot; wicket:id=&quot;yesButton&quot; value=&quot;Yes&quot; /&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/table&gt;
            &lt;/form&gt;
        &lt;/wicket:panel&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>and Java class:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p207code16'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20716"><td class="code" id="p207code16"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">pl.tdziurko.ajaxmodalwindowapp.areyousuremodal</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.AjaxRequestTarget</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.markup.html.form.AjaxButton</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.basic.MultiLineLabel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.form.Form</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.panel.Panel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">pl.tdziurko.ajaxmodalwindowapp.areyousuremodal.AreYouSurePanel.ConfirmationAnswer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> YesNoPanel <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Apanel+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Panel</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> YesNoPanel<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> id, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> message, <span style="color: #000000; font-weight: bold;">final</span> ModalWindow modalWindow, <span style="color: #000000; font-weight: bold;">final</span> ConfirmationAnswer answer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        Form yesNoForm <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;yesNoForm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        MultiLineLabel messageLabel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MultiLineLabel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span>, message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        yesNoForm.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>messageLabel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        modalWindow.<span style="color: #006633;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Please confirm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        modalWindow.<span style="color: #006633;">setInitialHeight</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        modalWindow.<span style="color: #006633;">setInitialWidth</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">350</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        AjaxButton yesButton <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AjaxButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;yesButton&quot;</span>, yesNoForm<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onSubmit<span style="color: #009900;">&#40;</span>AjaxRequestTarget target, Form form<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>target <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    answer.<span style="color: #006633;">setAnswer</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    modalWindow.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        AjaxButton noButton <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AjaxButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;noButton&quot;</span>, yesNoForm<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onSubmit<span style="color: #009900;">&#40;</span>AjaxRequestTarget target, Form form<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>target <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    answer.<span style="color: #006633;">setAnswer</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    modalWindow.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        yesNoForm.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>yesButton<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        yesNoForm.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>noButton<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        add<span style="color: #009900;">&#40;</span>yesNoForm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Everything looks pretty straightforward. We pass to the constructor text which will be displayed as a confirmation question, references to ModalWindow object in which YesNoPanel is placed and to ConfirmationAnswer object.<br />
ConfirmationAnswer class will be created in the next paragraph and will be used to store information whether user pressed &#8216;Yes&#8217; or &#8216;No&#8217; button in our panel.</p>
<p>Now it&#8217;s time to prepare wrapping form to our YesNoPanel. We could simply achieve it by creating panel with form and one button in it. In our example it will be AreYouSurePanel class:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p207code17'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20717"><td class="code" id="p207code17"><pre class="html" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE html
    PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns:wicket&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;/&gt;
        &lt;title&gt;&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;wicket:panel &gt;
            &lt;form wicket:id=&quot;confirmForm&quot; action=&quot;&quot; style=&quot;display: inline;&quot;&gt;
                &lt;input type=&quot;submit&quot; wicket:id=&quot;confirmButton&quot; value=&quot;Default name&quot; /&gt;
                &lt;span style=&quot;display: none;&quot; wicket:id=&quot;modal&quot;&gt;&lt;/span&gt;
            &lt;/form&gt;
        &lt;/wicket:panel&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>and in Java:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p207code18'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20718"><td class="code" id="p207code18"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">pl.tdziurko.ajaxmodalwindowapp.areyousuremodal</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.AjaxRequestTarget</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.markup.html.form.AjaxButton</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.form.Form</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.panel.Panel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.model.Model</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> AreYouSurePanel <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Apanel+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Panel</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> ModalWindow confirmModal<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> ConfirmationAnswer answer<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> Map<span style="color: #339933;">&lt;</span>string,string<span style="color: #339933;">&gt;</span> modifiersToApply<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AreYouSurePanel<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> id, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> buttonName, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> modalMessageText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        answer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ConfirmationAnswer<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        addElements<span style="color: #009900;">&#40;</span>id, buttonName, modalMessageText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> addElements<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> id, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> buttonName, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> modalMessageText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        confirmModal <span style="color: #339933;">=</span> createConfirmModal<span style="color: #009900;">&#40;</span>id, modalMessageText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        Form form <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;confirmForm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        add<span style="color: #009900;">&#40;</span>form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        AjaxButton confirmButton <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AjaxButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;confirmButton&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> Model<span style="color: #009900;">&#40;</span>buttonName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onSubmit<span style="color: #009900;">&#40;</span>AjaxRequestTarget target, Form form<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                confirmModal.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        form.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>confirmButton<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        form.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>confirmModal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> onConfirm<span style="color: #009900;">&#40;</span>AjaxRequestTarget target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> onCancel<span style="color: #009900;">&#40;</span>AjaxRequestTarget target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> ModalWindow createConfirmModal<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> id, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> modalMessageText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        ModalWindow modalWindow <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ModalWindow<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;modal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        modalWindow.<span style="color: #006633;">setCookieName</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        modalWindow.<span style="color: #006633;">setContent</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> YesNoPanel<span style="color: #009900;">&#40;</span>modalWindow.<span style="color: #006633;">getContentId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, modalMessageText, modalWindow, answer<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        modalWindow.<span style="color: #006633;">setWindowClosedCallback</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ModalWindow.<span style="color: #006633;">WindowClosedCallback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClose<span style="color: #009900;">&#40;</span>AjaxRequestTarget target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>answer.<span style="color: #006633;">isAnswer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    onConfirm<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                    onCancel<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> modalWindow<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConfirmationAnswer <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aserializable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Serializable</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> answer<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> ConfirmationAnswer<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> answer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">answer</span> <span style="color: #339933;">=</span> answer<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isAnswer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> answer<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAnswer<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> answer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">answer</span> <span style="color: #339933;">=</span> answer<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here we do following steps:</p>
<ol>
<li>Create form with one AjaxButton which shows modalWindow when clicked.</li>
<li>Create modalWindow with YesNoPanel in it. As mentioned earlier, we pass there references to our modal window and to confirmationAnswer object.</li>
<li>Add WindowClosedCallback to modalWindow and basing on user choice perform onConfirm or onCancel method. These methods are both abstract to force developer extending AreYouSurePanel to implement them according to his needs.</li>
</ol>
<p>That&#8217;s it, we are done. To test how it&#8217;s working we must change a bit our page class and html file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p207code19'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20719"><td class="code" id="p207code19"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html
    PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns:wicket=&quot;http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd&quot; &gt;
    &lt;head&gt;  
        &lt;title&gt;Wicket Ajax 'Are you sure?' Modal Window&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
        &lt;div align=&quot;center&quot;&gt;
            &lt;strong&gt;Wicket Ajax 'Are you sure?' Modal Window&lt;/strong&gt;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
            &lt;form action=&quot;&quot; wicket:id=&quot;formWithJavaScript&quot;&gt;
                &lt;input type=&quot;submit&quot; wicket:id=&quot;buttonWithJavaScript&quot; value=&quot;Action!&quot;/&gt;
            &lt;/form&gt;
        &lt;/div&gt;
&nbsp;
&nbsp;
&nbsp;
        &lt;div align=&quot;center&quot;&gt;
            &lt;span wicket:id=&quot;yesNoPanel&quot;/&gt;
        &lt;/div&gt;
&nbsp;
    &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>and</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p207code20'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20720"><td class="code" id="p207code20"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">pl.tdziurko.ajaxmodalwindowapp</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// imports omitted</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HomePage <span style="color: #000000; font-weight: bold;">extends</span> WebPage <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> HomePage<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> PageParameters parameters<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        Form formWithJavaScript <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;formWithJavaScript&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a> buttonWithJavaScript <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;buttonWithJavaScript&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onSubmit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Doing my job&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        buttonWithJavaScript.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SimpleAttributeModifier<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">&quot;onclick&quot;</span>, <span style="color: #0000ff;">&quot;if(!confirm('Do you really want to perform this action?')) return false;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        formWithJavaScript.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>buttonWithJavaScript<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        add<span style="color: #009900;">&#40;</span>formWithJavaScript<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        AreYouSurePanel yesNoPanel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AreYouSurePanel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;yesNoPanel&quot;</span>, <span style="color: #0000ff;">&quot;Ajax Action!&quot;</span>, <span style="color: #0000ff;">&quot;Do you really want to perform this action?&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onConfirm<span style="color: #009900;">&#40;</span>AjaxRequestTarget target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Doing my job after ajax modal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onCancel<span style="color: #009900;">&#40;</span>AjaxRequestTarget target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        add<span style="color: #009900;">&#40;</span>yesNoPanel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And after clicking &#8216;Ajax Action!&#8217; we could see that it&#8217;s working as intended:</p>
<p><img src="http://wicketbyexample.com/wp-content/uploads/2010/02/ajaxModalWindow.PNG.png" alt="" title="ajaxModalWindow.PNG" width="399" height="400" class="alignnone size-full wp-image-210" /></p>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/wicket-ajax-confirmation-modal-window/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New article about OpenID in Java, uses Wicket</title>
		<link>http://wicketbyexample.com/new-article-about-openid-in-java-uses-wicket/</link>
		<comments>http://wicketbyexample.com/new-article-about-openid-in-java-uses-wicket/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 16:58:11 +0000</pubDate>
		<dc:creator>ildella</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[wicket openid]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=203</guid>
		<description><![CDATA[Last week  I was searching  examples while working in integrating OpenID in a Java Web Applications and I found a very recent article (January 27th) on the IBM developerWorks.

OpenID for Java Web applications, Part 1 by J Steven Perry offer a panoramic about OpenID in a modern web applications and uses Apache Wicket [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Last week  I was searching  examples while working in integrating OpenID in a Java Web Applications and I found a very recent article (January 27th) on the IBM developerWorks.<br />
<a href="http://www.ibm.com/developerworks/java/library/j-openid/index.html"></a></p>
<p><a href="http://www.ibm.com/developerworks/java/library/j-openid/index.html">OpenID for Java Web applications, Part 1</a> by J Steven Perry offer a panoramic about OpenID in a modern web applications and uses Apache Wicket as Web framework for the example. The article is really good and offers the whole source code as download.</p>
<p>This article talk about implementing an OpenID consumer Service while the part two will focus on writing an OpenID provider.</p>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/new-article-about-openid-in-java-uses-wicket/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating HTML5 and Wicket</title>
		<link>http://wicketbyexample.com/integrating-html5-and-wicket/</link>
		<comments>http://wicketbyexample.com/integrating-html5-and-wicket/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 07:13:34 +0000</pubDate>
		<dc:creator>kinabalu</dc:creator>
				<category><![CDATA[Example]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache wicket]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=191</guid>
		<description><![CDATA[After following some of the debates raging about Apple&#8217;s new iPad and the future of Adobe&#8217;s Flash, the discussion usually turned to the coming future of HTML5.
Seeing as we love Apache Wicket at Mystic, I thought I&#8217;d tinker around to see how hard it would be to start adding some support for the new HTML5 [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>After following some of the debates raging about <a href="http://www.apple.com/ipad/" target="_blank">Apple&#8217;s new iPad</a> and the future of <a href="http://www.adobe.com/products/flashplayer/" target="_blank">Adobe&#8217;s Flash</a>, the discussion usually turned to the coming future of <a href="http://dev.w3.org/html5/spec/Overview.html" target="_blank">HTML5</a>.</p>
<p>Seeing as we love <a href="http://wicket.apache.org" target="_blank">Apache Wicket</a> at <a href="http://www.mysticcoders.com" target="_blank">Mystic</a>, I thought I&#8217;d tinker around to see how hard it would be to start adding some support for the new HTML5 tags.  There are quite a few examples out there that show off <code>canvas</code>, <code>geolocation</code>, <code>storage</code>, and of course <code>video</code> and <code>audio</code>.<br />
<span id="more-191"></span></p>
<p>First thing I set about doing, was to define the <code>video</code> tag.  It takes an optional <code>src</code> attribute among others, or multiple <code>source</code> tags for offering up different video streams for the browser to choose from.  Firefox uses Ogg Vorbis, and Safari uses H.264, so of course, the browser vendors still don&#8217;t agree.  Here&#8217;s some code to use what I&#8217;d want to see from a <code>video</code> component:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p191code26'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19126"><td class="code" id="p191code26"><pre class="java" style="font-family:monospace;">        <span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;</span> mm <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mm.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MediaSource<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/dizzy.mp4&quot;</span>, <span style="color: #0000ff;">&quot;video/mp4&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mm.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MediaSource<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/dizzy.ogv&quot;</span>, <span style="color: #0000ff;">&quot;video/ogg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        IModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;&gt;</span> mediaSourceList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AbstractReadOnlyModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;</span> getObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> mm<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Html5Video<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dizzy&quot;</span>, mediaSourceList<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> isControls<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> isAutoPlay<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We&#8217;ve defined a custom Object for use with our new <code>Html5Video</code> component, and it will hold the appropriate attributes we would need to output either a <code>src</code> attribute or a <code>source</code> tag.  You can also see from this example that we&#8217;ve got a few booleans we&#8217;re overriding by default, and more available in the actual implementation.  Let&#8217;s take a look at the <code>Html5Video</code> component:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p191code27'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19127"><td class="code" id="p191code27"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Html5Video <span style="color: #000000; font-weight: bold;">extends</span> Html5Media <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Html5Video<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> id, IModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;&gt;</span> model<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>id, model<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">int</span> getWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">int</span> getHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onComponentTag<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> ComponentTag tag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>getWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            tag.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;width&quot;</span>, getWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>getHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            tag.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;height&quot;</span>, getHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onComponentTag</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getTagName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;video&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So you can see we&#8217;ve abstracted this out even further into an <code>Html5Media</code> object which we&#8217;ll look at shortly.  For now, we have <code>width</code> and <code>height</code> which are specific to just the <code>video</code> tag.  And we&#8217;re also overriding <code>onComponentTag</code> to throw those attributes into the <code>video</code> tag if they aren&#8217;t zero.  We also steal from some ideas in wicket core, and implement a method in <code>Html5Media</code> to checkComponentTag based on the results of a method that can be overridden <code>getTagName</code>.</p>
<p>Let&#8217;s take a look at <code>Html5Media</code> which is where we&#8217;ll find most of the meat:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p191code28'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19128"><td class="code" id="p191code28"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Html5Media <span style="color: #000000; font-weight: bold;">extends</span> WebMarkupContainer <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> IModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;&gt;</span> sources<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Html5Media<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> id, <span style="color: #000000; font-weight: bold;">final</span> IModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;&gt;</span> model<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>id, model<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sources</span> <span style="color: #339933;">=</span> wrap<span style="color: #009900;">&#40;</span>model<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Html5UtilsBehavior<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>First thing we see, is we&#8217;re extending <code>WebMarkupContainer</code>, basically because our component can have body text (useful for fallback support).  Next you&#8217;ll see that we&#8217;re adding a behavior <code>Html5UtilsBehavior</code>.  The basic purpose is to header contribute a useful javascript file when working with browsers that don&#8217;t yet support HTML5 (Internet Explorer I&#8217;m looking at you!).  Some more code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p191code29'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19129"><td class="code" id="p191code29"><pre class="java" style="font-family:monospace;">    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onComponentTag<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> ComponentTag tag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> tagName <span style="color: #339933;">=</span> getTagName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tagName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            checkComponentTag<span style="color: #009900;">&#40;</span>tag, tagName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        List<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;</span> sources <span style="color: #339933;">=</span> getSources<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sources <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> sources.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            MediaSource source <span style="color: #339933;">=</span> sources.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            tag.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;src&quot;</span>, source.<span style="color: #006633;">getSrc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isAutoBuffer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            tag.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;autobuffer&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isAutoPlay<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            tag.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;autoplay&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isLoop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            tag.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;loop&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isControls<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            tag.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;controls&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Default handling for component tag</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onComponentTag</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getTagName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here we check the component tag to ensure it is the acceptable name.  Then if we only have a single source, we add this to the <code>video</code> tag instead of separate elements in the body.  The next bunch of statements pull from methods and add boolean attributes to the tag if they are true.  And we provide an implementation of <code>getTagName</code> that returns null as a sensible default.</p>
<p><code>onComponentTagBody</code> is where we optionally will define <code>source</code> tags and the optional attributes that go along with it:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p191code30'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19130"><td class="code" id="p191code30"><pre class="java" style="font-family:monospace;">    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onComponentTagBody<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> MarkupStream markupStream, <span style="color: #000000; font-weight: bold;">final</span> ComponentTag openTag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        List<span style="color: #339933;">&lt;</span>MediaSource<span style="color: #339933;">&gt;</span> sources <span style="color: #339933;">=</span> getSources<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sources <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> sources.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">final</span> AppendingStringBuffer buffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AppendingStringBuffer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> index <span style="color: #339933;">&lt;</span> sources.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> index<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">final</span> MediaSource source <span style="color: #339933;">=</span> sources.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;source &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;src='&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>source.<span style="color: #006633;">getSrc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>source.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; type='&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>source.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>source.<span style="color: #006633;">getMedia</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; media='&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>source.<span style="color: #006633;">getMedia</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; /&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            getResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>buffer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onComponentTagBody</span><span style="color: #009900;">&#40;</span>markupStream, openTag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here we&#8217;re ensuring things aren&#8217;t empty, and then if we have more than one source element (often the case for compatibility between Firefox and Safari), we&#8217;ll output each <code>source</code> tag.</p>
<p>We&#8217;ve also gone through the trouble of adding an implementation of <code>Html5Audio</code> which consisted of overriding the <code>getTagName</code> method and returning <code>audio</code>.  Pretty simple stuff.</p>
<p>When we put our example into place, we get a video with controls like so:</p>
<p><a href="http://wicketbyexample.com/wp-content/uploads/2010/01/Screen-shot-2010-01-31-at-10.59.53-PM.png"><img src="http://wicketbyexample.com/wp-content/uploads/2010/01/Screen-shot-2010-01-31-at-10.59.53-PM.png" alt="" title="Screen shot 2010-01-31 at 10.59.53 PM" width="496" height="425" class="alignnone size-full wp-image-198" /></a></p>
<p>So what&#8217;s next?  If you download the project available and linked below, it also contains an example of using the <code>audio</code> component.  The <code>Html5UtilsBehavior</code> gives us the ability to CSS style the new HTML5 tags even with Internet Explorer, so our code can be more semantic instead of littering it with div&#8217;s for lack of an alternative.  There are a ton more interactions and behaviors that can be added to support video and audio, support for canvas, postMessage,  storage, Web Database. Web Workers, geolocation, Content Editable, etc.  I have no reason to think any of these would be impossible to integrate into a sensible component with Wicket.</p>
<p>If you&#8217;d like to download the example and run it locally, or take a look at the components written, I&#8217;ve started a project over at Google Code called <a href="https://code.google.com/p/wicket-html5/" target="_blank">wicket-html5</a>.  Contact me if you&#8217;d like to contribute and start hacking away at some of these components.</p>
<p>To infinity, and beyond! </p>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/integrating-html5-and-wicket/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Latest Wicket Core Examples available via Simple URL</title>
		<link>http://wicketbyexample.com/latest-wicket-core-examples-available-via-simple-url/</link>
		<comments>http://wicketbyexample.com/latest-wicket-core-examples-available-via-simple-url/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 22:27:55 +0000</pubDate>
		<dc:creator>kinabalu</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=175</guid>
		<description><![CDATA[After a recent week long training Mystic gave a week ago, one item that came up was the examples as posted on the official Wicket website are a version behind.  Available here: http://www.wicketstuff.org/wicket13/.
In response to throwing up the latest javadoc at a simple to remember URL on this website, the examples seem to be [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>After a recent week long training Mystic gave a week ago, one item that came up was the examples as posted on the official Wicket website are a version behind.  Available here: <a href="http://www.wicketstuff.org/wicket13/" target="_blank">http://www.wicketstuff.org/wicket13/</a>.</p>
<p>In response to throwing up the latest javadoc at a simple to remember URL on this website, the examples seem to be the next logical step to make available.  So point your browser here:</p>
<p><a href="http://wicketbyexample.com/examples">http://wicketbyexample.com/examples</a></p>
<p>This is running the latest 1.4.6 release of Apache Wicket.  Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/latest-wicket-core-examples-available-via-simple-url/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wicket Javadoc Access Via Simple URL</title>
		<link>http://wicketbyexample.com/wicket-javadoc-access-via-simple-url/</link>
		<comments>http://wicketbyexample.com/wicket-javadoc-access-via-simple-url/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 05:56:00 +0000</pubDate>
		<dc:creator>kinabalu</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[javadoc]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=172</guid>
		<description><![CDATA[There are definitely times, that I wish I had easy access to the javadoc for something in the Wicket internals, without opening the IDE, or keeping my own local versions available.  
I usually resort to a quick Google search and unfortunately 9 / 10 I get a non-recent javadoc version.
Today I&#8217;ve gone through and [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>There are definitely times, that I wish I had easy access to the javadoc for something in the Wicket internals, without opening the IDE, or keeping my own local versions available.  </p>
<p>I usually resort to a quick Google search and unfortunately 9 / 10 I get a non-recent javadoc version.</p>
<p>Today I&#8217;ve gone through and downloaded all the core library javadocs for Wicket and as of version 1.4.6 they are all available from the following link:</p>
<p><a href="http://wicketbyexample.com/api">wicketbyexample.com/api</a></p>
<p>Click through to the library you&#8217;d like and get immediate access.  It follows a simple structure /api/&lt;module name&gt;/&lt;version&gt;/</p>
<p>That&#8217;s it.  Hope some of you find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/wicket-javadoc-access-via-simple-url/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Autocomplete with an Object</title>
		<link>http://wicketbyexample.com/autocomplete-with-an-object/</link>
		<comments>http://wicketbyexample.com/autocomplete-with-an-object/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 02:37:01 +0000</pubDate>
		<dc:creator>sswinsburg</dc:creator>
				<category><![CDATA[Example]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[AutoCompleteTextField]]></category>
		<category><![CDATA[wicketstuff]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=156</guid>
		<description><![CDATA[The Wicket Extensions package provides a neat component called the AutoCompleteTextField.
In a nutshell, this allows you to provide a TextField with a List of Strings and when you start typing, the ones that match the input show up. This is a great component, but consider this scenario:
You have a list of contacts, one of which [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>The Wicket Extensions package provides a neat component called the AutoCompleteTextField.</p>
<p>In a nutshell, this allows you to provide a TextField with a List of Strings and when you start typing, the ones that match the input show up. This is a great component, but consider this scenario:</p>
<p><em>You have a list of contacts, one of which you want to send an email to. Each person has a unique id and a name. You want to search based on their name, but send the message to their id.</em></p>
<pre>
class Person {
  long uuid;
  String displayName;
  String email;
  ...
}</pre>
<p>This is not possible with the AutoCompleteTextField, as it uses a list of Strings and will submit whatever is entered in the text field.<br />
What you need is to be able to separate the key from the value.</p>
<p>Enter the ObjectAutoCompleteTextField. This is a class from <a href="http://wicketstuff.org/confluence/display/STUFFWEB/Home">WicketStuff</a> and allows you to provide a List of Objects and tell the AutoCompleteTextField what value should be the displayed value, and what values should be submitted.</p>
<p>Firstly, the markup is the same as a normal text field:<br />
<code>&lt;input type="text" wicket:id="toField" /&gt;</code></p>
<p>Now lets build the parts we need:</p>
<p><strong>1.</strong> The list of objects:</p>
<pre>
final List contacts = dao.getContacts();
</pre>
<p><strong>2.</strong> The AutoCompletionChoicesProvider:</p>
<pre>
AutoCompletionChoicesProvider provider = new AutoCompletionChoicesProvider() {
	private static final long serialVersionUID = 1L;

	public Iterator getChoices(String input) {
		return logic.getMatchingContacts(contacts, input).iterator();
	}
};
</pre>
<p>This is called whenever the input changes and allows us to get a list of items from our master list that match the input. In this example we already have the list of contacts, so we just need to return an Iterator of the matches for that list. You could use something like this:</p>
<pre>
public List getMatchingContacts(List contacts, String search) {
	List subList = new ArrayList();

	for(Person p : connections){
		if(StringUtils.startsWithIgnoreCase(p.getDisplayName(), search)) {
			if(subList.size() == Constants.MAX_CONNECTIONS_PER_SEARCH) {
				break;
			}
			subList.add(p);
		}
	}
	return subList;
}
</pre>
<p><strong>3.</strong> The ObjectAutoCompleteRenderer:</p>
<pre>
ObjectAutoCompleteRenderer renderer = new ObjectAutoCompleteRenderer(){
	private static final long serialVersionUID = 1L;

	protected String getIdValue(Person p) {
		return p.getUuid();
	}
	protected String getTextValue(Person p) {
		return p.getDisplayName();
	}
};
</pre>
<p>This separates out the key from the value. From the Person class we want to use the uuid as the submitted value<br />
and the displayName as the one that shows up in the textfield and we search based on that.</p>
<p><strong>4.</strong> Putting it all together is the ObjectAutoCompleteBuilder which takes the provider and sets the renderer.</p>
<pre>
ObjectAutoCompleteBuilder builder = new ObjectAutoCompleteBuilder(provider);
builder.autoCompleteRenderer(renderer);
</pre>
<p><strong>5.</strong> Finally, we create the ObjectAutoCompleteField from the builder.</p>
<pre>
ObjectAutoCompleteField autocompleteField = builder.build("toField", new PropertyModel(newMessage, "to"));
final TextField toField = autocompleteField.getSearchTextField();
toField.setRequired(true);
form.add(autocompleteField);
</pre>
<p>We now have a textfield that allows us to search through a list of items but submit a different value associated with each of those items.<br />
<img src="http://wicketbyexample.com/wp-content/uploads/2010/01/autocomplete.png" alt="autocomplete" width="150" height="176" class="alignnone size-full wp-image-161" /></p>
<p><strong>Advanced tip:</strong><br />
Once we have found an item in the list, it is set into the TextField. If we want to clear the selection, by default the link is a textual [x]. We can override this to be whatever we want, different text, or even an Image.<br />
<img src="http://wicketbyexample.com/wp-content/uploads/2010/01/autocomplete_search.png" alt="autocomplete_search" width="113" height="36" class="alignnone size-full wp-image-162" /></p>
<p>To use an icon like in the example above, add something like this to the builder:</p>
<pre>
<code>builder.searchLinkImage(new ContextRelativeResource("images/cross.png"));</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/autocomplete-with-an-object/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Gravatar Image component for Wicket</title>
		<link>http://wicketbyexample.com/a-gravatar-image-component-for-wicket/</link>
		<comments>http://wicketbyexample.com/a-gravatar-image-component-for-wicket/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 15:35:40 +0000</pubDate>
		<dc:creator>kinabalu</dc:creator>
				<category><![CDATA[Example]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[gravatar]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[wicket1_4]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=141</guid>
		<description><![CDATA[The comment system that was added to mysticpaste.com several months ago was pretty bare, boring.  It consisted of capturing name, email, and the comment of which we show name and comment only.  Since we&#8217;re avid blog posters and readers, the thought of implementing a custom Wicket component for a Gravatar immediately came to [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>The comment system that was added to <a href="http://mysticpaste.com" target="_blank">mysticpaste.com</a> several months ago was pretty bare, boring.  It consisted of capturing name, email, and the comment of which we show name and comment only.  Since we&#8217;re avid blog posters and readers, the thought of implementing a custom Wicket component for a <a href="http://gravatar.com" target="_blank">Gravatar</a> immediately came to mind.</p>
<p>First things first, extend our new GravatarImage component from WebComponent.  We don&#8217;t need the image to hold any nested components, etc:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p141code34'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14134"><td class="code" id="p141code34"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GravatarImage <span style="color: #000000; font-weight: bold;">extends</span> WebComponent <span style="color: #009900;">&#123;</span></pre></td></tr></table></div>

<p>We also override onComponentTag so we can populate the &#8220;src&#8221; attribute for our image with the Gravatar generated URL:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p141code35'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14135"><td class="code" id="p141code35"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onComponentTag<span style="color: #009900;">&#40;</span>ComponentTag tag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onComponentTag</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        checkComponentTag<span style="color: #009900;">&#40;</span>tag, <span style="color: #0000ff;">&quot;img&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        tag.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;src&quot;</span>, getDefaultModelObjectAsString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Next we provide our own Model implementation which performs the MD5 magic on our email address to give its special Gravatar URL pointing to our image.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p141code36'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14136"><td class="code" id="p141code36"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> GravatarModel <span style="color: #000000; font-weight: bold;">extends</span> AbstractReadOnlyModel<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> GRAVATAR_URL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.gravatar.com/avatar/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> email<span style="color: #339933;">;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> gravatarKey<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> hsize<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> GravatarModel<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> model, <span style="color: #000066; font-weight: bold;">int</span> hsize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            email <span style="color: #339933;">=</span> model.<span style="color: #006633;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            gravatarKey <span style="color: #339933;">=</span> MD5Util.<span style="color: #006633;">md5Hex</span><span style="color: #009900;">&#40;</span>email<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">hsize</span> <span style="color: #339933;">=</span> hsize<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            StringBuilder sb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>GRAVATAR_URL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>gravatarKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;?s=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>hsize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> sb.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And that&#8217;s it!  Just follow the example given in the javadoc and voila!  You should have Gravatar pictures for the entered email address.  To take a look at the full implementation: <a href="http://kenai.com/projects/mystic-apps/sources/mystic-apps/content/mysticpaste/src/main/java/com/mysticcoders/mysticpaste/web/components/GravatarImage.java?rev=89" target="_blank">Download GravatarImage.java</a>.</p>
<h3>Next steps</h3>
<p>A couple of items can be added to this component to make it more &#8220;full-featured&#8221; to the Gravatar API.  Gravatar supports a default Gravatar image which may be passed, along with a number of flags one of which is implemented &#8220;s&#8221; or size.</p>
<p>Hope you enjoyed this, and use this in your next project!</p>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/a-gravatar-image-component-for-wicket/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enums internationalization with Wicket</title>
		<link>http://wicketbyexample.com/enums-internationalization-with-wicket/</link>
		<comments>http://wicketbyexample.com/enums-internationalization-with-wicket/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 15:30:07 +0000</pubDate>
		<dc:creator>ildella</dc:creator>
				<category><![CDATA[Example]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[wicket1_4]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=130</guid>
		<description><![CDATA[(Editor’s note: Olivier Croisier contributed this column from YesWicket.)
Enums are a convenient way to represent finite collections of elements : seasons, week days&#8230; As a consequence, they frequently need to be input or displayed in web applications &#8211; and it better be in a I18N-aware way.
Let&#8217;s see how easily Wicket can handle this.
Enums internationalization
Throughout this [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><em>(Editor’s note: <a href="http://yeswicket.com" target="_blank">Olivier Croisier</a> contributed this column from YesWicket.)</em></p>
<p>Enums are a convenient way to represent finite collections of elements : seasons, week days&#8230; As a consequence, they frequently need to be input or displayed in web applications &#8211; and it better be in a I18N-aware way.<br />
Let&#8217;s see how easily Wicket can handle this.</p>
<h2>Enums internationalization</h2>
<p>Throughout this article, we&#8217;ll use the Seasons Enum as an example :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code51'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13051"><td class="code" id="p130code51"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">enum</span> Season <span style="color: #009900;">&#123;</span>
    SPRING, SUMMER, AUTUMN, WINTER<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Wicket has a powerful hierarchical I18N system : given a logical I18N key (a string), the corresponding translation is first searched for at the current component level, then up its hierarchy &#8211; all the way up to the Application root if required.<br />
To benefit from it, the developer only has to call the getString() method on any Wicket component :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code52'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13052"><td class="code" id="p130code52"><pre class="java" style="font-family:monospace;"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> translation <span style="color: #339933;">=</span> anyComponent.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The first thing we need to do is therefore to devise a way to generate a unique I18N key for each Enum constant. The most obvious solution is to use their Fully Qualified Names as a key (eg. &#8220;com.yeswicket.wickettips.model.WINTER&#8221;) ; this should prevent fortuitous name clashes.</p>
<p>The following code snippet demonstrates how to get an Enum&#8217;s FQN :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code53'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13053"><td class="code" id="p130code53"><pre class="java" style="font-family:monospace;">Season enumValue <span style="color: #339933;">=</span> Season.<span style="color: #006633;">WINTER</span><span style="color: #339933;">;</span>
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> messageKey <span style="color: #339933;">=</span> enumValue.<span style="color: #006633;">getDeclaringClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCanonicalName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">+</span> enumValue.<span style="color: #006633;">name</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In order to avoid copy/pasting this code all around the application, and to be able to easily replace it with another algorithm should the need arise, we&#8217;ll use the Strategy pattern, where every algorithm is encapsulated in its own class.<br />
This might seem easy to implement, but keep in mind that every class accessible from a Wicket component will be serialized along with it in the session store&#8230; and that&#8217;s something you will definetely want to avoid.</p>
<p>Static methods to the rescue !<br />
The following class, inspired from java.util.Locale, has a static-only API for its consumers (thus solving the serialization concern) and still allows the underlying algorithm to be changed at will :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code54'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13054"><td class="code" id="p130code54"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> EnumMessageKeyProvider <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> EnumMessageKeyProvider provider <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DefaultEnumResourceKeyProvider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> EnumMessageKeyProvider getDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> EnumMessageKeyProvider.<span style="color: #006633;">provider</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> setDefault<span style="color: #009900;">&#40;</span>EnumMessageKeyProvider provider<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		EnumMessageKeyProvider.<span style="color: #006633;">provider</span> <span style="color: #339933;">=</span> provider<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Enum<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;&gt;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> computeMessageKey<span style="color: #009900;">&#40;</span>T enumValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Enum<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;&gt;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getMessageKey<span style="color: #009900;">&#40;</span>T enumValue<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> EnumMessageKeyProvider.<span style="color: #006633;">provider</span>.<span style="color: #006633;">computeMessageKey</span><span style="color: #009900;">&#40;</span>enumValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DefaultEnumResourceKeyProvider <span style="color: #000000; font-weight: bold;">extends</span> EnumMessageKeyProvider <span style="color: #009900;">&#123;</span>
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Enum<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;&gt;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> computeMessageKey<span style="color: #009900;">&#40;</span>T enumValue<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> enumValue.<span style="color: #006633;">getDeclaringClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCanonicalName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">+</span> enumValue.<span style="color: #006633;">name</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Getting an I18N key for an Enum is now as easy as :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code55'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13055"><td class="code" id="p130code55"><pre class="java" style="font-family:monospace;">Season enumValue <span style="color: #339933;">=</span> Season.<span style="color: #006633;">WINTER</span><span style="color: #339933;">;</span>
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #339933;">=</span> EnumMessageKeyProvider.<span style="color: #006633;">getMessageKey</span><span style="color: #009900;">&#40;</span>enumValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>To use another key generation algorithm, just write a new strategy&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code56'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13056"><td class="code" id="p130code56"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleNameEnumResourceKeyProvider <span style="color: #000000; font-weight: bold;">extends</span> EnumMessageKeyProvider <span style="color: #009900;">&#123;</span>
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Enum<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;&gt;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> computeMessageKey<span style="color: #009900;">&#40;</span>T enumValue<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> enumValue.<span style="color: #006633;">name</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>&#8230;and register it with the EnumMessageKeyProvider ; a good place for that is the Application&#8217;s init() method :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code57'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13057"><td class="code" id="p130code57"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WicketTipsApplication <span style="color: #000000; font-weight: bold;">extends</span> WebApplication <span style="color: #009900;">&#123;</span>
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		EnumMessageKeyProvider.<span style="color: #006633;">setDefault</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SimpleNameEnumResourceKeyProvider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#40;</span>...<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Displaying internationalized enums</h2>
<p>Wicket&#8217;s Label is a very basic component that simply displays the text provided by its Model.<br />
To display Enums, we can develop a new kind of Model that automatically performs internationalization and hands over the resulting text to the component it is attached to.</p>
<p>As an example, we&#8217;ll extend the very convenient PropertyModel.<br />
Please note that our Model provides a String but operates on an Enum : EnumPropertyModel<T extends Enum<T>> extends PropertyModel<String>. Also, in addition to the PropertyModel&#8217;s existing constructor parameters (the target object and the name of the property to retrieve), our class needs a Component to call the getString() method on.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code58'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13058"><td class="code" id="p130code58"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EnumPropertyModel<span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Enum<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> PropertyModel<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acomponent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Component</span></a> component<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> EnumPropertyModel<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> modelObject, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> expression, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acomponent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Component</span></a> resourceProvider<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>modelObject, expression<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">component</span> <span style="color: #339933;">=</span> resourceProvider<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> expression <span style="color: #339933;">=</span> propertyExpression<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> target <span style="color: #339933;">=</span> getTarget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>target <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			T enumValue <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>T<span style="color: #009900;">&#41;</span> PropertyResolver.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span>expression, target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #339933;">=</span> EnumMessageKeyProvider.<span style="color: #006633;">getMessageKey</span><span style="color: #009900;">&#40;</span>enumValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> component.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This custom Model can now be used with a Label (and many other components) to easily display any Enum :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code59'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13059"><td class="code" id="p130code59"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HomePage <span style="color: #000000; font-weight: bold;">extends</span> WebPage <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Season season <span style="color: #339933;">=</span> Season.<span style="color: #006633;">SPRING</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> HomePage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alabel+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Label</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;label&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> EnumPropertyModel<span style="color: #339933;">&lt;</span>Season<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;season&quot;</span>, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Selecting an enum with a DropDownChoice</h2>
<p>Now that we can display an Enum, let&#8217;s see how to let the user choose one from a dropdown list.</p>
<p>The DropDownChoice component follows the MVC pattern :</p>
<ul>
<li>The DropDownChoice itself is the Controller</li>
<li>The Model it takes as a parameter is, obviously, the Model</li>
<li>The View is rendered by a ChoiceRenderer that is responsible for the HTML <option> tags generation.</li>
</ul>
<p>Usually, the DropDownChoice relies on the Model to define the set of selectable values. With Enums, those values are determined by the Enum&#8217;s type itself, so we can bypass the Model and override the DropDownChoice&#8217;s &#8220;getChoices()&#8221; method :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code60'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13060"><td class="code" id="p130code60"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EnumDropDownChoice<span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Enum<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> DropDownChoice<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> EnumDropDownChoice<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> id, IModel<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> model<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		setModel<span style="color: #009900;">&#40;</span>model<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		setChoiceRenderer<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> EnumChoiceRenderer<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> EnumDropDownChoice<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> id, IModel<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> model, EnumChoiceRenderer<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> choiceRenderer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		setModel<span style="color: #009900;">&#40;</span>model<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		setChoiceRenderer<span style="color: #009900;">&#40;</span>choiceRenderer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> T<span style="color: #339933;">&gt;</span> getChoices<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarrays+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Arrays</span></a>.<span style="color: #006633;">asList</span><span style="color: #009900;">&#40;</span>getModelObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDeclaringClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getEnumConstants</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The related ChoiceRenderer will generate the <option> tags using the Enum&#8217;s name as an identifier, and its internationalized value as a label :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code61'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13061"><td class="code" id="p130code61"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EnumChoiceRenderer<span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Enum<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">implements</span> IChoiceRenderer<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/** The Component used a the root of the I18N search process */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acomponent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Component</span></a> resourceProvider<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> EnumChoiceRenderer<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acomponent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Component</span></a> resourceProvider<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">resourceProvider</span> <span style="color: #339933;">=</span> resourceProvider<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> getDisplayValue<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> T value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> key <span style="color: #339933;">=</span> EnumMessageKeyProvider.<span style="color: #006633;">getMessageKey</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> resourceProvider.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getIdValue<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> T object, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">final</span> Enum<span style="color: #339933;">&lt;?&gt;</span> enumValue <span style="color: #339933;">=</span> object<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> enumValue.<span style="color: #006633;">name</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Finally, here is an example of how our components can be used to select and display an Enum in a standart Form :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code62'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13062"><td class="code" id="p130code62"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HomePage <span style="color: #000000; font-weight: bold;">extends</span> WebPage <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Season season <span style="color: #339933;">=</span> Season.<span style="color: #006633;">SPRING</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> HomePage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Form<span style="color: #339933;">&lt;</span>Void<span style="color: #339933;">&gt;</span> form <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #339933;">&lt;</span>Void<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;form&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		form.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> EnumDropDownChoice<span style="color: #339933;">&lt;</span>Season<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;season&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> PropertyModel<span style="color: #339933;">&lt;</span>Season<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;season&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		add<span style="color: #009900;">&#40;</span>form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alabel+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Label</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;label&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> EnumPropertyModel<span style="color: #339933;">&lt;</span>Season<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;season&quot;</span>, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>In action</h2>
<p>The complete source code is available at the bottom of this article.<br />
Feel free to play with it to see all those custom components in live action. The example form comes with two additional links, to switch between the French and English locales and see the internationalization magic happen.</p>
<p>Last note : a Gradle build script is provided to help you get started in seconds. Just run the following command in the application&#8217;s directory. Gradle will automatically compile the classes, copy the required resources, and start a Jetty server.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code63'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13063"><td class="code" id="p130code63"><pre class="java" style="font-family:monospace;">gradle jettyRun</pre></td></tr></table></div>

<p>Then, open a browser at :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p130code64'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13064"><td class="code" id="p130code64"><pre class="java" style="font-family:monospace;">http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:8080/Wicket-tips/</span></pre></td></tr></table></div>

<p>Have fun !</p>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/enums-internationalization-with-wicket/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wicket TinyMCE: some advanced tips</title>
		<link>http://wicketbyexample.com/wicket-tinymce-some-advanced-tips/</link>
		<comments>http://wicketbyexample.com/wicket-tinymce-some-advanced-tips/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 20:04:01 +0000</pubDate>
		<dc:creator>ildella</dc:creator>
				<category><![CDATA[Example]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[HeaderContributor]]></category>
		<category><![CDATA[tinymce]]></category>
		<category><![CDATA[wicketstuff]]></category>

		<guid isPermaLink="false">http://wicketbyexample.com/?p=101</guid>
		<description><![CDATA[Some tricks to use TinyMCE wicket integration in a real application: toggle behavior on and off with user interactions, submit a form via ajax with a tinyMCE component inside.]]></description>
			<content:encoded><![CDATA[<p></p><p>Wicket offers a valid integration with the powerful and open source <a href="http://tinymce.moxiecode.com/">TinyMCE</a>, a Javascript HTML WYSIWYG editor. Wicket-contrib-tinymce is part of the wicketstuff-core and is well done and maintained. Then using TinyMCE within wicket is very easy and the <a href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicket-contrib-tinymce">instructions on the site</a> would be enough to make things work and the example project on the subversion repository will do most of the rest.</p>
<p><span id="more-101"></span></p>
<p>Here I want to tell something I have learned using this nice toy.</p>
<p><strong>Use with Maven 2</strong></p>
<p>To use tinymce in a Maven 2 project, we need to add the wicketstuff maven2 repository:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p101code65'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10165"><td class="code" id="p101code65"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>wicket-stuff<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://wicketstuff.org/maven/repository<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>and, of course, the dependency</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p101code66'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10166"><td class="code" id="p101code66"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.wicketstuff<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tinymce<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.4-SNAPSHOT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><strong>Creating a CheckBox that toggle TinyMceBehavior on and off.</strong></p>
<p>In my scenario I need the user to enable Rich Text capabilities for a field in a form. Is nothing complicated but we need to take care about when to instantiate objects. In my solution, I use a checkbox to toggle the state. This is the code I have in the constructor of my panel.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p101code67'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10167"><td class="code" id="p101code67"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CustomPanel <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Apanel+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Panel</span></a> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> TinyMceBehavior tinyMceBehavior<span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">public</span> CustomPanel<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> id, IModel model<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       ...
      <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atextarea+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">TextArea</span></a> field <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atextarea+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">TextArea</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span>, model<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
      tinyMceBehavior <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TinyMceBehavior<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      PropertyModel richProperty <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PropertyModel<span style="color: #009900;">&#40;</span>model, <span style="color: #0000ff;">&quot;rich&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>richProperty.<span style="color: #006633;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         field.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tinyMceBehavior<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AjaxCheckBox<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;switchRte&quot;</span>, richProperty<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
         @Override
         <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onUpdate<span style="color: #009900;">&#40;</span>AjaxRequestTarget target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>getModelObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               field.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tinyMceBehavior<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
               field.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>tinyMceBehavior<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               tinyMceBehavior <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TinyMceBehavior<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            target.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>CustomPanel.<span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The information is saved in a property called &#8220;rich&#8221; in my domain object so it is persisted and I can remember next time. That object is already wrapped in the variable <em>model</em> (a wicket IModel) that in this code is wrapped in a simple wicket PropertyModel. In this example I have used Wicket 1.4 support for generics.</p>
<p><strong>Switching to Rich Text after the page is load</strong></p>
<p>One of the problem I had was that my page loaded without any TinyMCEBehavior attached to any component. User can enable the behavior at runtime like in the example before. Well, it did not work because the javascript needs to be load at the time the page is loaded. The solution is that when you have some TinyMCE components in your page, is better that in the constructor of the page you load the Javascript this way:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p101code68'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10168"><td class="code" id="p101code68"><pre class="java" style="font-family:monospace;">      add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> HeaderContributor<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IHeaderContributor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> renderHead<span style="color: #009900;">&#40;</span>IHeaderResponse response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            response.<span style="color: #006633;">renderJavascriptReference</span><span style="color: #009900;">&#40;</span>TinyMCESettings.<span style="color: #006633;">javaScriptReference</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Subtle trick: submit via Ajax</strong></p>
<p>Maybe anyone knew this before. I did not. When you submit a form containing a TinyMCE component and the form submits via ajax, say an AjaxSubmitLink or an AjaxButton in Wicket, you *must* use a trick as someone else <a href="http://dwairi.blogspot.com/2006/12/tinymce-ajax.html">already explained</a>. With wicket-tinymce this becomes adding the <em>TinyMceAjaxSubmitModifier</em> to the submit component and that&#8217;s all.</p>
<p><strong>Conclusion</strong></p>
<p>wicket-contrib-tinymce is a well done contribution to the wicketstuff-core and an important library for web developer that uses Wicket. The only small point is that is actually using a one year old version of TinyMCE, dated august 2008. It does the *most* of the stuff and I never felt the need to upgrade. Maybe someone just need some feature or a bug fix present in more recent release. Hope that wicket-tinymce developer will have some time to play with newer TinyMCE.</p>
<p>This is my first contribution to WicketByExample. I hope you liked the article, I will like any feedback. Cheers.<br />
<a href="http://twitter.com/ildella" target="_blank"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://wicketbyexample.com/wicket-tinymce-some-advanced-tips/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
