<?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>wicket praxis &#187; html</title>
	<atom:link href="http://www.wicket-praxis.de/blog/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wicket-praxis.de/blog</link>
	<description>erfahrungen mit wicket aus dem projektalltag</description>
	<lastBuildDate>Fri, 26 Aug 2011 11:14:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>E-Mail mit Wicket verschicken</title>
		<link>http://www.wicket-praxis.de/blog/2009/12/01/sending-html-email-from-wicket-app/</link>
		<comments>http://www.wicket-praxis.de/blog/2009/12/01/sending-html-email-from-wicket-app/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 06:59:14 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Technologie]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[sending]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=204</guid>
		<description><![CDATA[Wäre es nicht praktisch, wenn man eine E-Mail verschicken könnte, in dem man die Komponenten, die man für die Darstellung auf der Webseite verwendet, auch für das Erstellen der E-Mail heranziehen könnte. Das Unterfangen ist leider nicht trivial, weil man nicht ohne Weiteres um die &#8220;Magie&#8221;, die Wicket an vielen Stellen benutzt, herum kommt. Nun [...]]]></description>
			<content:encoded><![CDATA[<p>Wäre es nicht praktisch, wenn man eine E-Mail verschicken könnte, in dem man die Komponenten, die man für die Darstellung auf der Webseite verwendet, auch für das Erstellen der E-Mail heranziehen könnte. Das Unterfangen ist leider nicht trivial, weil man nicht ohne Weiteres um die &#8220;Magie&#8221;, die Wicket an vielen Stellen benutzt, herum kommt. Nun bietet Wicket die Möglichkeit, Komponenten und Seiten, Formulare und vieles mehr in Unit-Test zu testen. Was liegt also näher, als diese Funktionalität für unsere Zwecke zu missbrauchen.</p>
<p><strong>Die E-Mail</strong></p>
<p>Als erstes erstellen wir eine Seite, die den Inhalt der E-Mail erzeugen soll:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Java(TM) 2 Platform Standard Edition 5.0"><div class="devcodeoverflow"><ol><li><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.wicketpraxis.web.blog.pages.questions.email</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.WebPage</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.basic.Label</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.list.ListItem</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.list.ListView</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.model.IModel</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EmailContentPage <span style="color: #000000; font-weight: bold;">extends</span> WebPage</li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> EmailContentPage<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span><span style="color: #003399; font-weight: bold;">List</span><span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">String</span><span style="color: #339933;">&gt;&gt;</span> list<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">ListView</span><span style="color: #339933;">&lt;</span><span style="color: #003399; font-weight: bold;">String</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;list&quot;</span>,list<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@<span style="color: #003399; font-weight: bold;">Override</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> populateItem<span style="color: #009900;">&#40;</span>ListItem<span style="color: #339933;">&lt;</span><span style="color: #003399; font-weight: bold;">String</span><span style="color: #339933;">&gt;</span> item<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span>,item.<span style="color: #006633;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li><span style="color: #009900;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Der Code soll zeigen, dass Komponenten ganz normal Funktionieren. Deshalb bekommt die Seite von außen eine Liste mit Werten übergeben, die dann durch eine ListView dargestellt wird.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="HTML"><div class="devcodeoverflow"><ol><li><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>TestEmail<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span></li><li><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;list&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span></li><li><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Im Markup habe ich absichtlich den &#8220;Rahmen&#8221; der Seite (html > body) weggelassen. Die Klasse und das Markup dienen in diesem Beispiel nur als Platzhalter.</p>
<p><strong>Darstellen und Abschicken</strong></p>
<p>In Wicket sind sehr viele Objekte an den aktuellen Thread gebunden. Das ist notwendig, damit man nicht eine ganze Liste von Objekten als Übergabeparameter durch Methodenaufrufe schleifen muss. Das ist allerdings genau dann ein Problem, wenn wir innerhalb einer Wicketanwendung eine andere Seite darstellen möchten. Außerdem ist es ein Problem, wenn es wie in einem im Hintergrund laufenden Prozess überhaupt keine WicketApplication gibt. Daher erstellen wir uns ein paar Hilfsklassen, die sich um dieses Problem kümmern.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Java(TM) 2 Platform Standard Edition 5.0"><div class="devcodeoverflow"><ol><li><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.wicketpraxis.web.blog.pages.questions.email</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> WicketCallback<span style="color: #339933;">&lt;</span>I,O<span style="color: #339933;">&gt;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> O getResult<span style="color: #009900;">&#40;</span>I input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #009900;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Java(TM) 2 Platform Standard Edition 5.0"><div class="devcodeoverflow"><ol><li><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.wicketpraxis.web.blog.pages.questions.email</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Logger</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WicketThreadAdapter<span style="color: #339933;">&lt;</span>I,O<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Thread</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&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: #003399; font-weight: bold;">Logger</span> _logger = <span style="color: #003399; font-weight: bold;">Logger</span>.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>WicketThreadAdapter.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #003399; font-weight: bold;">Object</span> _lock=<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">Object</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;WicketCallback<span style="color: #339933;">&lt;</span>I, O<span style="color: #339933;">&gt;</span> _callback<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;I _input<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;O _output<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #006600; font-weight: bold;">boolean</span> _done=<span style="color: #006600; font-weight: bold;">false</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> WicketThreadAdapter<span style="color: #009900;">&#40;</span>WicketCallback<span style="color: #339933;">&lt;</span>I, O<span style="color: #339933;">&gt;</span> callback, I input<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_callback=callback<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_input=input<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;@<span style="color: #003399; font-weight: bold;">Override</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #009900;">&#40;</span>_lock<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_output=_callback.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span>_input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_done=<span style="color: #006600; font-weight: bold;">true</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_lock.<span style="color: #006633;">notify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> O getResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">InterruptedException</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #009900;">&#40;</span>_lock<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;&nbsp;&nbsp;font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>_done<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_lock.<span style="color: #006633;">wait</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">return</span> _output<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&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>I,O<span style="color: #339933;">&gt;</span> O getResult<span style="color: #009900;">&#40;</span>WicketCallback<span style="color: #339933;">&lt;</span>I, O<span style="color: #339933;">&gt;</span> callback, I input<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">InterruptedException</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;WicketThreadAdapter<span style="color: #339933;">&lt;</span>I,O<span style="color: #339933;">&gt;</span> threadAdapter = <span style="color: #000000; font-weight: bold;">new</span> WicketThreadAdapter<span style="color: #339933;">&lt;</span>I,O<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>callback,input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;threadAdapter.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">return</span> threadAdapter.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li><span style="color: #009900;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Die WicketThreadAdapter-Klasse wird über die statische Methode getResult(&#8230;) angesprochen und macht folgendes: Es wird ein neuer Thread erzeugt. Im laufenden Thread wird der Callback aufgerufen und der Thread beendet. Das Ergebnis, das im Thread ermittelt wurde, wird als Ergebnis herausgereicht. Kurz: Das Ergebnis wird in einem anderen Thread als dem aktuellen ermittelt und führt so nicht zu Kollisionen mit der laufenden Anwendung.</p>
<p><strong>Der Trick</strong></p>
<p>Das alles führt noch nicht zum Ziel. Wir müssen uns jetzt noch darum kümmern, dass wir die Seite dargestellt bekommen. Dazu benutzten wir die Klasse BaseWicketTester, die sich um alles weitere kümmert. Dort übergeben wir die Seite, die wir darstellen wollen. Dann können wir auf den Inhalt der Seite zugreifen und als Ergebnis zurück liefern. </p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Java(TM) 2 Platform Standard Edition 5.0"><div class="devcodeoverflow"><ol><li><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.wicketpraxis.web.blog.pages.questions.email</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Arrays</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.WebPage</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.markup.html.basic.Label</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.model.IModel</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.model.Model</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.util.tester.BaseWicketTester</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EmailFromComponentPage <span style="color: #000000; font-weight: bold;">extends</span> WebPage</li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> EmailFromComponentPage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;WicketCallback<span style="color: #339933;">&lt;</span><span style="color: #003399; font-weight: bold;">List</span><span style="color: #339933;">&lt;</span><span style="color: #003399; font-weight: bold;">String</span><span style="color: #339933;">&gt;</span>, <span style="color: #003399; font-weight: bold;">String</span><span style="color: #339933;">&gt;</span> callback = <span style="color: #000000; font-weight: bold;">new</span> WicketCallback<span style="color: #339933;">&lt;</span><span style="color: #003399; font-weight: bold;">List</span><span style="color: #339933;">&lt;</span><span style="color: #003399; font-weight: bold;">String</span><span style="color: #339933;">&gt;</span>, <span style="color: #003399; font-weight: bold;">String</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">String</span> getResult<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">List</span><span style="color: #339933;">&lt;</span><span style="color: #003399; font-weight: bold;">String</span><span style="color: #339933;">&gt;</span> input<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">final</span> IModel<span style="color: #339933;">&lt;</span><span style="color: #003399; font-weight: bold;">List</span><span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">String</span><span style="color: #339933;">&gt;&gt;</span> listModel = Model.<span style="color: #006633;">ofList</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BaseWicketTester tester=<span style="color: #000000; font-weight: bold;">new</span> BaseWicketTester<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tester.<span style="color: #006633;">startPage</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> EmailContentPage<span style="color: #009900;">&#40;</span>listModel<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">return</span> tester.<span style="color: #006633;">getServletResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #003399; font-weight: bold;">String</span> result<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">try</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = WicketThreadAdapter.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span>callback, <span style="color: #003399; font-weight: bold;">Arrays</span>.<span style="color: #006633;">asList</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Klaus&quot;</span>,<span style="color: #0000ff;">&quot;Susi&quot;</span>,<span style="color: #0000ff;">&quot;Bert&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">InterruptedException</span> e<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result=e.<span style="color: #006633;">getLocalizedMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;email&quot;</span>,result<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setEscapeModelStrings</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li><span style="color: #009900;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Damit das Ergebnis richtig angezeigt wird, teilen wir dem Label &#8220;email&#8221; mit, dass es den Text nicht umschreiben soll.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="HTML"><div class="devcodeoverflow"><ol><li><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Email Form Component<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;Email <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span></li><li><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Wenn man die Seite aufruft, erhält man dann folgende Darstellung:</p>
<div id="attachment_207" class="wp-caption aligncenter" style="width: 335px"><img src="http://www.wicket-praxis.de/blog/wp-content/uploads/2009/12/wicket-email.png" alt="Ergebnis: Html-E-Mail aus Wicket" title="wicket-email" width="325" height="195" class="size-full wp-image-207" />
<p class="wp-caption-text">Ergebnis: Html-E-Mail aus Wicket</p>
</div>
<p>Wenn man die E-Mail durch Hintergrundprozesse versenden möchte, ist ein eigener Thread unnötig, weil keine WicketApplication-Klasse an den Thread gebunden ist. Dann sollte der Einsatz der BaseWicketTester-Klasse reichen. Es ist allerdings darauf zu achten, dass alles, was in der eigenen Application-Klasse definiert wurde, an dieser Stelle nicht ohne weiteres zur Verfügung steht (z.B. wird der OpenSessionInViewFilter für Spring nicht aufgerufen, die SpringBean-Annotationen sind ebenfalls funktionslos).</p>
<p><strong>Fazit</strong></p>
<p>Auch wenn sicher noch die eine oder andere Anpassung notwendig ist, damit man Komponenten sowohl für die Anwendung als auch für den E-Mail-Versand benutzten kann, lohnt sich der Aufwand, weil man a) auf die vielfältigen Möglichkeiten, die Wicket als &#8220;Template-Engine&#8221; bietet, zurückgreifen kann, b) man sich im besten Fall doppelten Code ersparen kann und c) man keine zweite Lösung einbinden muss. Und wieder hat mich Wicket ein wenig überrascht. Weil es dann doch so einfach ging:)</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F12%2F01%2Fsending-html-email-from-wicket-app%2F&amp;title=E-Mail%20mit%20Wicket%20verschicken&amp;bodytext=W%C3%A4re%20es%20nicht%20praktisch%2C%20wenn%20man%20eine%20E-Mail%20verschicken%20k%C3%B6nnte%2C%20in%20dem%20man%20die%20Komponenten%2C%20die%20man%20f%C3%BCr%20die%20Darstellung%20auf%20der%20Webseite%20verwendet%2C%20auch%20f%C3%BCr%20das%20Erstellen%20der%20E-Mail%20heranziehen%20k%C3%B6nnte.%20Das%20Unterfangen%20ist%20leider%20nicht%20trivial%2C" title="Digg"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F12%2F01%2Fsending-html-email-from-wicket-app%2F" title="Sphinn"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F12%2F01%2Fsending-html-email-from-wicket-app%2F&amp;title=E-Mail%20mit%20Wicket%20verschicken&amp;notes=W%C3%A4re%20es%20nicht%20praktisch%2C%20wenn%20man%20eine%20E-Mail%20verschicken%20k%C3%B6nnte%2C%20in%20dem%20man%20die%20Komponenten%2C%20die%20man%20f%C3%BCr%20die%20Darstellung%20auf%20der%20Webseite%20verwendet%2C%20auch%20f%C3%BCr%20das%20Erstellen%20der%20E-Mail%20heranziehen%20k%C3%B6nnte.%20Das%20Unterfangen%20ist%20leider%20nicht%20trivial%2C" title="del.icio.us"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F12%2F01%2Fsending-html-email-from-wicket-app%2F&amp;t=E-Mail%20mit%20Wicket%20verschicken" title="Facebook"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F12%2F01%2Fsending-html-email-from-wicket-app%2F&amp;title=E-Mail%20mit%20Wicket%20verschicken" title="Mixx"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F12%2F01%2Fsending-html-email-from-wicket-app%2F&amp;title=E-Mail%20mit%20Wicket%20verschicken&amp;annotation=W%C3%A4re%20es%20nicht%20praktisch%2C%20wenn%20man%20eine%20E-Mail%20verschicken%20k%C3%B6nnte%2C%20in%20dem%20man%20die%20Komponenten%2C%20die%20man%20f%C3%BCr%20die%20Darstellung%20auf%20der%20Webseite%20verwendet%2C%20auch%20f%C3%BCr%20das%20Erstellen%20der%20E-Mail%20heranziehen%20k%C3%B6nnte.%20Das%20Unterfangen%20ist%20leider%20nicht%20trivial%2C" title="Google Bookmarks"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
<div id="vgwpixel"></div><h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>16. Juni 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/06/16/wicket-ohne-template/" title="Wicket ohne Template">Wicket ohne Template</a></li><li>29. April 2011 -- <a href="http://www.wicket-praxis.de/blog/2011/04/29/wicket-back-button-detect/" title="Wicket &#8211; Back Button zuverlässig erkennen">Wicket &#8211; Back Button zuverlässig erkennen</a></li><li>24. Oktober 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/10/24/wicket-mainstream-github-mongodb/" title="Wicket &#8211; Mainstream, Github, MongoDB">Wicket &#8211; Mainstream, Github, MongoDB</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2009/12/01/sending-html-email-from-wicket-app/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Wicket ohne Template</title>
		<link>http://www.wicket-praxis.de/blog/2009/06/16/wicket-ohne-template/</link>
		<comments>http://www.wicket-praxis.de/blog/2009/06/16/wicket-ohne-template/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 19:13:06 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Technologie]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[desktop]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=62</guid>
		<description><![CDATA[Ich spiele seit einiger Zeit mit dem Gedanken, ob man basierend auf Wicket Komponenten entwickelt, die alle das entsprechende eigene Template mitbringen. Auf diese Weise könnte man dann Webanwendungen entwickeln, ohne eine Zeile Html-Code schreiben zu müssen. Verrückte Idee? Normalerweise reduziert sich die Arbeit mit dem Html-Templates auf das Anordnen der Komponenten. Das was übrig [...]]]></description>
			<content:encoded><![CDATA[<p>Ich spiele seit einiger Zeit mit dem Gedanken, ob man basierend auf Wicket Komponenten entwickelt, die alle das entsprechende eigene Template mitbringen. Auf diese Weise könnte man dann Webanwendungen entwickeln, ohne eine Zeile Html-Code schreiben zu müssen. Verrückte Idee?</p>
<p>Normalerweise reduziert sich die Arbeit mit dem Html-Templates auf das Anordnen der Komponenten. Das was übrig bleibt (eine paar div-Tags), sollte man durch den Einsatz von Layout-Komponenten ersetzen können. Dann programmiert man wie für eine Desktopanwendung und das Ergebnis sieht gleich entsprechend gut aus, wenn man zu die passende CSS-Datei mitliefert.</p>
<p>Bis jetzt fehlt mir noch der geeignete Ansatz und die Entscheidung für ein CSS-Framework. Für Empfehlungen und Tipps bin ich in dieser Phase sehr empfänglich. <img src='http://www.wicket-praxis.de/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F06%2F16%2Fwicket-ohne-template%2F&amp;title=Wicket%20ohne%20Template&amp;bodytext=Ich%20spiele%20seit%20einiger%20Zeit%20mit%20dem%20Gedanken%2C%20ob%20man%20basierend%20auf%20Wicket%20Komponenten%20entwickelt%2C%20die%20alle%20das%20entsprechende%20eigene%20Template%20mitbringen.%20Auf%20diese%20Weise%20k%C3%B6nnte%20man%20dann%20Webanwendungen%20entwickeln%2C%20ohne%20eine%20Zeile%20Html-Code%20schreiben%20" title="Digg"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F06%2F16%2Fwicket-ohne-template%2F" title="Sphinn"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F06%2F16%2Fwicket-ohne-template%2F&amp;title=Wicket%20ohne%20Template&amp;notes=Ich%20spiele%20seit%20einiger%20Zeit%20mit%20dem%20Gedanken%2C%20ob%20man%20basierend%20auf%20Wicket%20Komponenten%20entwickelt%2C%20die%20alle%20das%20entsprechende%20eigene%20Template%20mitbringen.%20Auf%20diese%20Weise%20k%C3%B6nnte%20man%20dann%20Webanwendungen%20entwickeln%2C%20ohne%20eine%20Zeile%20Html-Code%20schreiben%20" title="del.icio.us"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F06%2F16%2Fwicket-ohne-template%2F&amp;t=Wicket%20ohne%20Template" title="Facebook"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F06%2F16%2Fwicket-ohne-template%2F&amp;title=Wicket%20ohne%20Template" title="Mixx"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.wicket-praxis.de%2Fblog%2F2009%2F06%2F16%2Fwicket-ohne-template%2F&amp;title=Wicket%20ohne%20Template&amp;annotation=Ich%20spiele%20seit%20einiger%20Zeit%20mit%20dem%20Gedanken%2C%20ob%20man%20basierend%20auf%20Wicket%20Komponenten%20entwickelt%2C%20die%20alle%20das%20entsprechende%20eigene%20Template%20mitbringen.%20Auf%20diese%20Weise%20k%C3%B6nnte%20man%20dann%20Webanwendungen%20entwickeln%2C%20ohne%20eine%20Zeile%20Html-Code%20schreiben%20" title="Google Bookmarks"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
<div id="vgwpixel"></div><h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>1. Dezember 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/12/01/sending-html-email-from-wicket-app/" title="E-Mail mit Wicket verschicken">E-Mail mit Wicket verschicken</a></li><li>29. April 2011 -- <a href="http://www.wicket-praxis.de/blog/2011/04/29/wicket-back-button-detect/" title="Wicket &#8211; Back Button zuverlässig erkennen">Wicket &#8211; Back Button zuverlässig erkennen</a></li><li>24. Oktober 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/10/24/wicket-mainstream-github-mongodb/" title="Wicket &#8211; Mainstream, Github, MongoDB">Wicket &#8211; Mainstream, Github, MongoDB</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2009/06/16/wicket-ohne-template/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 14/39 queries in 0.035 seconds using disk: basic
Object Caching 854/877 objects using disk: basic

Served from: www.wicket-praxis.de @ 2012-02-06 20:00:11 -->
