<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>footprint code coverage &#187; FreeMarker</title>
	<atom:link href="http://www.footprint.de/fcc/tag/freemarker/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.footprint.de/fcc</link>
	<description>Thoughts and rants on programming.</description>
	<lastBuildDate>Thu, 28 May 2009 05:44:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Five things&#8230;</title>
		<link>http://www.footprint.de/fcc/2009/02/five-things/</link>
		<comments>http://www.footprint.de/fcc/2009/02/five-things/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 14:40:42 +0000</pubDate>
		<dc:creator>Jan Kriesten</dc:creator>
				<category><![CDATA[Scala]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[Compass]]></category>
		<category><![CDATA[FreeMarker]]></category>
		<category><![CDATA[iBATIS]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Lucene]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quartz]]></category>
		<category><![CDATA[TestNG]]></category>

		<guid isPermaLink="false">http://www.footprint.de/fcc/?p=44</guid>
		<description><![CDATA[A couple of days ago I had a discussion on what would be the five libraries a developer should have had a good look at. This naturally is depending on what type of programming you&#8217;re focusing on, so you will seldom get the same list by two different developers.
Let&#8217;s define some base parameters: web application [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago I had a discussion on what would be the five libraries a developer should have had a good look at. This naturally is depending on what type of programming you&#8217;re focusing on, so you will seldom get the same list by two different developers.</p>
<p>Let&#8217;s define some base parameters: web application development with the JVM as targeted platform (choose your poison: Java, Scala, &#8230;). Here&#8217;s my list and some hints on why I think them more worth than one look:</p>
<dl>
<dt><a href="http://wicket.apache.org/"><strong>Wicket</strong></a></dt>
<dd>Nothings more thought-thru for developing web applications.</dd>
<dt><a href="http://ibatis.apache.org/"><strong>iBATIS</strong></a></dt>
<dd>There&#8217;s a big hype about all those ORMs like <a href="http://hibernate.org/">Hibernate</a> or <a href="http://www.eclipse.org/eclipselink/">EclipseLink</a>. But when it comes to performance, flexibility and easyness, I think iBATIS the better approach. It&#8217;s very mature and with the upcoming next major release (a beta will be availabe in Q1 this year hopefully) it&#8217;ll gain some Java 5 toys to play with.</dd>
<dt><a href="http://www.opensymphony.com/quartz/"><strong>Quartz</strong></a></dt>
<dd>When in need of scheduling tasks one shouldn&#8217;t have to bother on implementing anything else than the tasks. There are few libraries as mature and reliable as well as easy to develop with as this one.</dd>
<dt><a href="http://www.compass-project.org/"><strong>Compass</strong></a></dt>
<dd>Built on top of <a href="http://lucene.apache.org/java/docs/">Lucene</a> this library simplifys integrating search into you applications immensely!</dd>
<dt><a href="http://testng.org/"><strong>TestNG</strong></a></dt>
<dd>I think unit tests are overrated when you look at how they&#8217;re used in many cases &#8211; often it&#8217;s just for numbers and not quality testing. Every programmer should and needs to dive a bit deeper into this matter!</dd>
</dl>
<p>I left out other great libraries cause they don&#8217;t appear as often in my projects but are nonetheless very valuable. Among these are (for the records): <a href="http://code.google.com/p/google-guice/">Guice</a>, <a href="http://freemarker.sourceforge.net/">FreeMarker</a>, <a href="http://www.jfree.org/jfreechart/">JFreeChart</a>, <a href="http://www.lowagie.com/iText/">iText</a>, <a href="http://static.springsource.org/spring-security/site/">SpringSecurity</a>, <a href="http://joda-time.sourceforge.net/">Joda Time</a>, <a href="http://logback.qos.ch/">LOGBack</a>.</p>
<p>And did I say that all of you should use <a href="http://www.scala-lang.org/"><strong>Scala</strong></a>?! <img src='http://www.footprint.de/fcc/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Best regards, &#8212; Jan.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.footprint.de/fcc/2009/02/five-things/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some Wicke[dt] Scala</title>
		<link>http://www.footprint.de/fcc/2008/11/some-wicket-scala/</link>
		<comments>http://www.footprint.de/fcc/2008/11/some-wicket-scala/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 18:45:27 +0000</pubDate>
		<dc:creator>Jan Kriesten</dc:creator>
				<category><![CDATA[Scala]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[Dynamic Components]]></category>
		<category><![CDATA[FreeMarker]]></category>
		<category><![CDATA[Velocity]]></category>

		<guid isPermaLink="false">http://www.footprint.de/fcc/?p=17</guid>
		<description><![CDATA[Apache Wicket is a cool web framework to develop with. I&#8217;m in that business for some time now and I still haven&#8217;t found any nicer &#8211; really! JSF is no match at all, and since I&#8217;m doing most of my programming in Scala I&#8217;d taken a brief look at Lift. But that&#8217;s not mine, either. [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Apache Wicket" href="http://wicket.apache.org/" target="_blank">Apache Wicket</a> is a cool web framework to develop with. I&#8217;m in that business for some time now and I still haven&#8217;t found any nicer &#8211; really! JSF is no match at all, and since I&#8217;m doing most of my programming in Scala I&#8217;d taken a brief look at <a title="Lift" href="http://www.liftweb.net/" target="_blank">Lift</a>. But that&#8217;s not mine, either. Everything in Wicket is ad-hoc reusable, that&#8217;s what I like best about it. And I think of Wicket and Scala as the perfect combination to develop with: Scala&#8217;s traits allow adding and overriding things so easy to Wicket components that it&#8217;s just a joy!</p>
<p>I want to add some foundations to above statements, so be prepared for some tough Wicket internal stuff &#8211; easily written in Scala! And for the readers still developing Wicket applications in Java: You might find the resulting library equally useful and should be able to use it from Java as well.</p>
<h3>Enter the Quest</h3>
<p>You may have found yourself in need to preprocess the markup for your Wicket components. Typically, you like using <a title="FreeMarker Templating Library" href="http://freemarker.org/" target="_blank">FreeMarker</a> or <a title="Velocity Templating Library" href="http://velocity.apache.org/" target="_blank">Velocity</a> for that. There are Wicket projects which provide you with some kind of support to do so. But those only go half the way. You can load template files and process them, but you can&#8217;t add Wicket components in them! Actually you could using <code>&lt;wicket:component&gt;</code> &#8211; but that&#8217;s a) not officially supported and b) doesn&#8217;t work when adding components with Ajax behaviors, since those components are coming in in a late stage in Wicket&#8217;s rendering scheme. Suppose you want to add some self-updating RSS feed panels based on some markup coming from a database you&#8217;re lost here.</p>
<h3>The solution: <em>Dynamo</em></h3>
<p>I had such a task and found myself writing a generalized template engine with support for dynamic Wicket components. Here&#8217;s a short code example how it&#8217;s working:</p>

<div class="wp_codebox"><table width="100%" ><tr id="p174"><td class="code" id="p17code4"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">class</span> FreemarkerApplication <span style="color: #0000ff; font-weight: bold;">extends</span> WebApplication <span style="color: #0000ff; font-weight: bold;">with</span> Dynamo <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> getTemplateEngine<span style="color: #000080;">:</span> TemplateEngine <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> FreemarkerEngine<span style="color: #F78811;">&#40;</span> appPath, <span style="color: #0000ff; font-weight: bold;">new</span> Properties, Locale.<span style="color: #000000;">GERMAN</span> <span style="color: #F78811;">&#41;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> getHomePage <span style="color: #000080;">=</span> classOf<span style="color: #F78811;">&#91;</span>FreemarkerDynamoPage<span style="color: #F78811;">&#93;</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">class</span> FreemarkerPage <span style="color: #0000ff; font-weight: bold;">extends</span> WebPage <span style="color: #0000ff; font-weight: bold;">with</span> TemplateContainer <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> getTemplateName <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;DynamoPage.ftl&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> getParameterMap <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> java.<span style="color: #000000;">util</span>.<span style="color: #000000;">Map</span><span style="color: #F78811;">&#91;</span>String,AnyRef<span style="color: #F78811;">&#93;</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">class</span> FreemarkerDynamoPage <span style="color: #0000ff; font-weight: bold;">extends</span> FreemarkerPage <span style="color: #0000ff; font-weight: bold;">with</span> DynamicComponentContainer</pre></td></tr></table></div>

<p>That&#8217;s it! All logic is hidden behind the scenes, you just have to know it works. Your dynamic code might add components in the following way:</p>

<div class="wp_codebox"><table width="100%" ><tr id="p175"><td class="code" id="p17code5"><pre class="html" style="font-family:monospace;">    &lt;h3&gt;Dynamic Wicket Components:&lt;/h3&gt;
    &lt;#list StringList as s&gt;
      &lt;dynComponent
        class=&quot;de.footprint.wicket.application.dynamo.TextPanel&quot;
        label=&quot;${s}&quot; /&gt;
    &lt;/#list&gt;</pre></td></tr></table></div>

<h3>But how?</h3>
<p>There were three tasks to accomplish. First was to define a general interface to call the processed template file. That wasn&#8217;t too difficult:</p>

<div class="wp_codebox"><table width="100%" ><tr id="p176"><td class="code" id="p17code6"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">trait</span> TemplateEngine <span style="color: #F78811;">&#123;</span>
  <span style="color: #000080;">@</span>throws<span style="color: #F78811;">&#40;</span> classOf<span style="color: #F78811;">&#91;</span>ResourceStreamNotFoundException<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#41;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> processTemplate<span style="color: #F78811;">&#40;</span> templateName<span style="color: #000080;">:</span> String, parameter<span style="color: #000080;">:</span> java.<span style="color: #000000;">util</span>.<span style="color: #000000;">Map</span><span style="color: #F78811;">&#91;</span>String,AnyRef<span style="color: #F78811;">&#93;</span>, locale<span style="color: #000080;">:</span> Locale <span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> String
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> resetCache<span style="color: #000080;">:</span> Unit
<span style="color: #F78811;">&#125;</span></pre></td></tr></table></div>

<p>Second was to hook into the markup loader to call on the engine whenever a container of type <code>TemplateContainer</code> was required. The <code>Dynamo</code> trait registers a customzed <code>MarkupCache</code> with the <code>Application</code> which just does that.</p>
<p>The third task was to add the dynamic component stuff. Now it got a bit nasty. The resource stream had to be filtered for components added by the template engine &#8211; and that had to happen before Wicket got it&#8217;s hand on the resources, i.e. <code>WicketTagIdentifier</code> got on the resource. So, the markup had to be loaded manually beforehand and the additional components had to be given unique (and stable) wicket:id&#8217;s. Having all that, the components only had to be created and added with their correct <code>wicket:id</code>. Easy, huh?</p>
<p>The nice thing with Scala is, you can just hide all these tasks in traits and add them to the components. <code>onBeforeRender</code> will just be overriden and mixed in, so the functionality is magically just there.</p>
<h3>Famous last words</h3>
<p>The code is here: <a href="http://www.footprint.de/fcc/wp-content/uploads/2008/11/wicket-dynamo.zip">Dynamo</a></p>
<p>To run the examples you have to use <code>mvn resin:run</code>.</p>
<p>It includes general support for FreeMarker and Velocity, but this approach can easily be integrated with any other markup source provider.</p>
<p>I hope you find this useful and get some ideas how Scala/Wicket can boost your code &#8211; not only in function but also in readability.</p>
<p>&#8212; Jan. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.footprint.de/fcc/2008/11/some-wicket-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

