<?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; Refactoring</title>
	<atom:link href="http://www.wicket-praxis.de/blog/category/refactoring/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wicket-praxis.de/blog</link>
	<description>erfahrungen mit wicket aus dem projektalltag</description>
	<lastBuildDate>Thu, 15 Jul 2010 07:13:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Wicket &#8211; Flexibilität mit Factories</title>
		<link>http://www.wicket-praxis.de/blog/2010/07/15/wicket-flexibilitat-mit-factories/</link>
		<comments>http://www.wicket-praxis.de/blog/2010/07/15/wicket-flexibilitat-mit-factories/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 07:13:46 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[factory]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=270</guid>
		<description><![CDATA[Komplexe Komponenten entstehen in Wicket durch das zusammenfügen von einfacheren Komponenten. Dabei werden die verwendeten Komponenten direkt adressiert. Nach außen ist nicht sichtbar, wie sich eine Komponente zusammensetzt. Um von dieser Komponente eine leicht abgewandelte Form zu erstellen, kann man auf z.B. Vererbung zurückgreifen, Komponenten ausblenden, das Markup überschreiben. Je mehr Variationen nötig sind, desto [...]]]></description>
			<content:encoded><![CDATA[<p>Komplexe Komponenten entstehen in Wicket durch das zusammenfügen von einfacheren Komponenten. Dabei werden die verwendeten Komponenten direkt adressiert. Nach außen ist nicht sichtbar, wie sich eine Komponente zusammensetzt. Um von dieser Komponente eine leicht abgewandelte Form zu erstellen, kann man auf z.B. Vererbung zurückgreifen, Komponenten ausblenden, das Markup überschreiben. Je mehr Variationen nötig sind, desto komplizierter wird der Aufbau. Der Aufwand steigt erheblich an.</p>
<p>Einen Ausweg aus dieser Situation könnte die Verwendung von Factories liefern. Dazu benötigen wir ein sehr einfach gehaltenes Interface:<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.factories</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.Component</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> IComponentFactory<span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;T newComponent<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Eine einfach Implementierung, die immer ein Label mit einem bestimmten Text liefert, können wir wie folgt implementieren:<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.factories</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.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>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LabelFactory <span style="color: #000000; font-weight: bold;">implements</span> IComponentFactory<span style="color: #339933;">&lt;</span>Label<span style="color: #339933;">&gt;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;?&gt;</span> _model<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> LabelFactory<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;?&gt;</span> model<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_model = model<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: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Label</span> newComponent<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<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;">return</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>id,_model<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></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Wir übergeben hierbei ein Model, das durch das Label angezeigt wird. Soll ein anderer Text angezeigt werden, muss man dafür eine neue Factory erstellen. Bis jetzt ist noch kein Vorteil dieser Lösung absehbar. Deshalb steigern wir etwas die Komplexität. Wir erstellen eine Factory, die einen Rahmen um eine Komponente ziehen kann. Dabei wird für die Darstellung das style-Attribut erweitert.<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.factories</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.AttributeModifier</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.Component</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.behavior.AttributeAppender</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.WebMarkupContainer</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.panel.Panel</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> BorderPanelFactory <span style="color: #000000; font-weight: bold;">implements</span> IComponentFactory<span style="color: #339933;">&lt;</span>Panel<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;">private</span> <span style="color: #000000; font-weight: bold;">final</span> IComponentFactory<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span> _content<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> IModel<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> _style<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> BorderPanelFactory<span style="color: #009900;">&#40;</span>IComponentFactory<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span> content, IModel<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> style<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_content = content<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_style = style<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: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Panel</span> newComponent<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> BorderPanel<span style="color: #009900;">&#40;</span>id, _content, _style<span style="color: #009900;">&#41;</span><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: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> BorderPanel <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Panel</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> BorderPanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id,IComponentFactory<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span> content,IModel<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> style<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WebMarkupContainer border=<span style="color: #000000; font-weight: bold;">new</span> WebMarkupContainer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;border&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>content.<span style="color: #006633;">newComponent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;content&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;&nbsp;&nbsp;border.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AttributeAppender<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;style&quot;</span>, <span style="color: #006600; font-weight: bold;">true</span>, style,<span style="color: #0000ff;">&quot;;&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;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>border<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><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--><br />
Wir übergeben daher eine Factory, die Komponenten erzeugt und ein Model, dass die Styleattribute beinhaltet. In dem Panel, was innerhalb der Factory erzeugt wird, wir dann eine Komponente eingebunden (&#8220;content&#8221;), die aus der übergebenen Factory kommt. Wir benötigen noch eine passende Markup-Datei (BorderPanelFactory$BorderPanel.html):<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="HTML"><div class="devcodeoverflow"><ol><li><span style="color: #009900;">&lt;wicket:panel&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;border&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;padding: 8px&quot;</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;wicket:container wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>wicket:container&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></li><li><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>wicket:panel&gt;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Um zu demonstrieren, welche Flexibilität man mit diesen wenigen Klassen bereits erreicht hat, verwenden wir beide Factories in einem Beispiel:<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.factories</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.model.Model</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> ComponentFactoryPage <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> ComponentFactoryPage<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;Model<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> redBorderStyle = Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;border:1px solid red; background-color: #fff0f0;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;Model<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> greenBorderStyle = Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;border:1px solid green; background-color: #f0fff0;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;Model<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> blueBorderStyle = Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;border:1px solid blue; background-color: #f0f0ff;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;LabelFactory haveFunLabelFactory = <span style="color: #000000; font-weight: bold;">new</span> LabelFactory<span style="color: #009900;">&#40;</span>Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Have Fun&quot;</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;&nbsp;&nbsp;BorderPanelFactory redBorderHasFunFactory = <span style="color: #000000; font-weight: bold;">new</span> BorderPanelFactory<span style="color: #009900;">&#40;</span>haveFunLabelFactory,redBorderStyle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;BorderPanelFactory greenBorderWrapsRedFactory = <span style="color: #000000; font-weight: bold;">new</span> BorderPanelFactory<span style="color: #009900;">&#40;</span>redBorderHasFunFactory,greenBorderStyle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;BorderPanelFactory blueBorderWrapsAllFactory = <span style="color: #000000; font-weight: bold;">new</span> BorderPanelFactory<span style="color: #009900;">&#40;</span>greenBorderWrapsRedFactory,blueBorderStyle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>blueBorderWrapsAllFactory.<span style="color: #006633;">newComponent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;element&quot;</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></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Wir erstellen 3 Modelle mit unterschiedlichen Werten für das style-Attribut. Um etwas Text anzuzeigen benutzen wir die LabelFactory. Danach werden drei BorderPanelFactory-Instanzen erzeugt, die eine andere Factory &#8220;umwickelt&#8221;. Zum Schluss wird ein Element erzeugt und in der Seite benutzt. Das Markup ist entsprechend einfach:<br />
<!--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>ComponentFactory Page<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;<span style="color: #009900;">&lt;wicket:container wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;element&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>wicket:container&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>Das Ergebnis sieht dann wie folgt aus:<br />
<a href="http://www.wicket-praxis.de/blog/wp-content/uploads/2010/07/wicket-component-factory.jpg"><img src="http://www.wicket-praxis.de/blog/wp-content/uploads/2010/07/wicket-component-factory-450x72.jpg" alt="" title="Wicket Component Factory Beispiel" width="450" height="72" class="aligncenter size-medium wp-image-271" /></a></p>
<p>Um zu zeigen, wie schnell die Möglichkeiten wachsen, die man mit diesem Ansatz abdecken kann, erstellen wir eine weitere Factory. In diesem Fall möchten wir zwei Elemente nebeneinander dargestellen:<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.factories</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.Component</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.panel.Panel</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> TwoInARowFactory <span style="color: #000000; font-weight: bold;">implements</span> IComponentFactory<span style="color: #339933;">&lt;</span>Component<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;">private</span> <span style="color: #000000; font-weight: bold;">final</span> IComponentFactory<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span> _left<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> IComponentFactory<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span> _right<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> TwoInARowFactory<span style="color: #009900;">&#40;</span>IComponentFactory<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span> left, IComponentFactory<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span> right<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_left = left<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_right = right<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: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Component</span> newComponent<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ContainerPanel<span style="color: #009900;">&#40;</span>id, _left, _right<span style="color: #009900;">&#41;</span><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: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> ContainerPanel <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Panel</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> ContainerPanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id,IComponentFactory<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span> left, IComponentFactory<span style="color: #339933;">&lt;?</span> <span style="color: #000000; font-weight: bold;">extends</span> Component<span style="color: #339933;">&gt;</span> right<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>left.<span style="color: #006633;">newComponent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;left&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;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>right.<span style="color: #006633;">newComponent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;right&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;<span style="color: #009900;">&#125;</span></li><li><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--><br />
Es werden daher zwei Factories übergeben, die dann für die Erzeugung des linken und des rechten Elements zuständig sind. Das Markup benutzt der Einfachheit halber Html-Tabellen für die Anordnung:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="HTML"><div class="devcodeoverflow"><ol><li><span style="color: #009900;">&lt;wicket:panel&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;wicket:container wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>wicket:container&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;wicket:container wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;right&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>wicket:container&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></li><li><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>wicket:panel&gt;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Unsere Seitenklasse ergänzen wir entsprechend:<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.factories</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.model.Model</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> ComponentFactoryPage <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> ComponentFactoryPage<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;Model<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> redBorderStyle = Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;border:1px solid red; background-color: #fff0f0;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;Model<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> greenBorderStyle = Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;border:1px solid green; background-color: #f0fff0;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;Model<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> blueBorderStyle = Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;border:1px solid blue; background-color: #f0f0ff;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;LabelFactory haveFunLabelFactory = <span style="color: #000000; font-weight: bold;">new</span> LabelFactory<span style="color: #009900;">&#40;</span>Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Have Fun&quot;</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;&nbsp;&nbsp;BorderPanelFactory redBorderHasFunFactory = <span style="color: #000000; font-weight: bold;">new</span> BorderPanelFactory<span style="color: #009900;">&#40;</span>haveFunLabelFactory,redBorderStyle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;BorderPanelFactory greenBorderWrapsRedFactory = <span style="color: #000000; font-weight: bold;">new</span> BorderPanelFactory<span style="color: #009900;">&#40;</span>redBorderHasFunFactory,greenBorderStyle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;BorderPanelFactory blueBorderWrapsAllFactory = <span style="color: #000000; font-weight: bold;">new</span> BorderPanelFactory<span style="color: #009900;">&#40;</span>greenBorderWrapsRedFactory,blueBorderStyle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>blueBorderWrapsAllFactory.<span style="color: #006633;">newComponent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;element&quot;</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;&nbsp;&nbsp;TwoInARowFactory twoInARowFactory = <span style="color: #000000; font-weight: bold;">new</span> TwoInARowFactory<span style="color: #009900;">&#40;</span>redBorderHasFunFactory, greenBorderWrapsRedFactory<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>twoInARowFactory.<span style="color: #006633;">newComponent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;two&quot;</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></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Das Markup muss ebenfalls angepasst werden:<br />
<!--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>ComponentFactory Page<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;<span style="color: #009900;">&lt;wicket:container wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;element&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>wicket:container&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;wicket:container wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;two&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>wicket:container&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>Das Ergebnis kann sich sehen lassen:<br />
<a href="http://www.wicket-praxis.de/blog/wp-content/uploads/2010/07/wicket-component-factory-split.jpg"><img src="http://www.wicket-praxis.de/blog/wp-content/uploads/2010/07/wicket-component-factory-split-450x128.jpg" alt="" title="Wicket Component Factory Split" width="450" height="128" class="aligncenter size-medium wp-image-272" /></a></p>
<p>Wie man an diesem Beispiel sehr gut erkennen kann, liegt in diesem Ansatz sehr viel Potential, gerade wenn die Anforderungen an die Flexibilität sehr hoch sind. In Projekten, die eine hohe Flexibilität erforderten hat sich dieses System bereits erfolgreich bewährt. Dabei kommt eine Kombinationen aus dem &#8220;klassischen&#8221; und dem Factory-Ansatz zum Einsatz, wodurch sich die meisten Anforderungen wesentlich besser abdecken lassen.</p>
<p>Gibt es noch ganz andere Lösungsstrategien?</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%2F2010%2F07%2F15%2Fwicket-flexibilitat-mit-factories%2F&amp;title=Wicket%20-%20Flexibilit%C3%A4t%20mit%20Factories&amp;bodytext=Komplexe%20Komponenten%20entstehen%20in%20Wicket%20durch%20das%20zusammenf%C3%BCgen%20von%20einfacheren%20Komponenten.%20Dabei%20werden%20die%20verwendeten%20Komponenten%20direkt%20adressiert.%20Nach%20au%C3%9Fen%20ist%20nicht%20sichtbar%2C%20wie%20sich%20eine%20Komponente%20zusammensetzt.%20Um%20von%20dieser%20Komponent" 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%2F2010%2F07%2F15%2Fwicket-flexibilitat-mit-factories%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%2F2010%2F07%2F15%2Fwicket-flexibilitat-mit-factories%2F&amp;title=Wicket%20-%20Flexibilit%C3%A4t%20mit%20Factories&amp;notes=Komplexe%20Komponenten%20entstehen%20in%20Wicket%20durch%20das%20zusammenf%C3%BCgen%20von%20einfacheren%20Komponenten.%20Dabei%20werden%20die%20verwendeten%20Komponenten%20direkt%20adressiert.%20Nach%20au%C3%9Fen%20ist%20nicht%20sichtbar%2C%20wie%20sich%20eine%20Komponente%20zusammensetzt.%20Um%20von%20dieser%20Komponent" 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%2F2010%2F07%2F15%2Fwicket-flexibilitat-mit-factories%2F&amp;t=Wicket%20-%20Flexibilit%C3%A4t%20mit%20Factories" 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%2F2010%2F07%2F15%2Fwicket-flexibilitat-mit-factories%2F&amp;title=Wicket%20-%20Flexibilit%C3%A4t%20mit%20Factories" 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%2F2010%2F07%2F15%2Fwicket-flexibilitat-mit-factories%2F&amp;title=Wicket%20-%20Flexibilit%C3%A4t%20mit%20Factories&amp;annotation=Komplexe%20Komponenten%20entstehen%20in%20Wicket%20durch%20das%20zusammenf%C3%BCgen%20von%20einfacheren%20Komponenten.%20Dabei%20werden%20die%20verwendeten%20Komponenten%20direkt%20adressiert.%20Nach%20au%C3%9Fen%20ist%20nicht%20sichtbar%2C%20wie%20sich%20eine%20Komponente%20zusammensetzt.%20Um%20von%20dieser%20Komponent" 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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>5. Januar 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/01/05/wicket-lose-koppelung-von-komponenten/" title="Wicket &#8211; lose Koppelung von Komponenten">Wicket &#8211; lose Koppelung von Komponenten</a></li><li>16. Oktober 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/10/16/wicket-component-overview/" title="Wicket Komponentenübersicht">Wicket Komponentenübersicht</a></li><li>14. April 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/04/14/wicket-eclipse-plugin-qwickie/" title="Wicket Eclipse Plugin &#8211;  qwickie">Wicket Eclipse Plugin &#8211;  qwickie</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2010/07/15/wicket-flexibilitat-mit-factories/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wicket &#8211; No TransparentResolver</title>
		<link>http://www.wicket-praxis.de/blog/2010/01/20/wicket-no-transparentresolver/</link>
		<comments>http://www.wicket-praxis.de/blog/2010/01/20/wicket-no-transparentresolver/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 09:16:14 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[init]]></category>
		<category><![CDATA[lazy]]></category>
		<category><![CDATA[transparent resolver]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=240</guid>
		<description><![CDATA[Wie ich im letzten Beitrag bereits angkündigt habe, kann man tatsächlich das TransparentResolver-Problem mit Hilfe der verzögerten Initialisierung lösen. Dazu muss die AbstractLazyPanel-Klasse nur ein wenig verändert werden.
package de.wicketpraxis.web.blog.pages.questions.transparent.lazy;&#160;import org.apache.wicket.Component;import org.apache.wicket.MarkupContainer;import org.apache.wicket.markup.html.panel.Panel;&#160;public abstract class AbstractLazyPanel extends Panel&#123;&#160;&#160;boolean _lazyInitCalled;&#160;&#160;&#160;public AbstractLazyPanel&#40;String id&#41;&#160;&#160;&#123;&#160;&#160;&#160;&#160;super&#40;id&#41;;&#160;&#160;&#125;&#160;&#160;&#160;@Override&#160;&#160;protected void onBeforeRender&#40;&#41;&#160;&#160;&#123;&#160;&#160;&#160;&#160;if &#40;!_lazyInitCalled&#41;&#160;&#160;&#160;&#160;&#123;&#160;&#160;&#160;&#160;&#160;&#160;_lazyInitCalled=true;&#160;&#160;&#160;&#160;&#160;&#160;lazyInit&#40;&#41;;&#160;&#160;&#160;&#160;&#125;&#160;&#160;&#160;&#160;super.onBeforeRender&#40;&#41;;&#160;&#160;&#125;&#160;&#160;&#160;protected abstract MarkupContainer lazyInit&#40;&#41;;&#125;
Die Methode lazyInit() liefert die Komponente zurück, unter der alle [...]]]></description>
			<content:encoded><![CDATA[<p>Wie ich im letzten Beitrag bereits angkündigt habe, kann man tatsächlich das TransparentResolver-Problem mit Hilfe der verzögerten Initialisierung lösen. Dazu muss die AbstractLazyPanel-Klasse nur ein wenig verändert werden.</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.transparent.lazy</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.Component</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.MarkupContainer</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.panel.Panel</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;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> AbstractLazyPanel <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Panel</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #006600; font-weight: bold;">boolean</span> _lazyInitCalled<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> AbstractLazyPanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><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;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> onBeforeRender<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;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>_lazyInitCalled<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;_lazyInitCalled=<span style="color: #006600; font-weight: bold;">true</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lazyInit<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;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onBeforeRender</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>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> MarkupContainer lazyInit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Die Methode lazyInit() liefert die Komponente zurück, unter der alle Kindkomponenten eingehangen werden müssen. Das sieht in eigenen Komponenten dann wie folgt aus:</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.transparent.lazy</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.MarkupContainer</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.WebMarkupContainer</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;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> BasePanel <span style="color: #000000; font-weight: bold;">extends</span> AbstractLazyPanel</li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> BasePanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><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;">protected</span> MarkupContainer lazyInit<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;WebMarkupContainer border = <span style="color: #000000; font-weight: bold;">new</span> WebMarkupContainer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;border&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>border<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> border<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Hier erstellen wir einen Container, den wir an ein div-Tag binden.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="HTML"><div class="devcodeoverflow"><ol><li><span style="color: #009900;">&lt;wicket:panel&gt;</span></li><li>&nbsp;&nbsp;Base</li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;border:1px solid blue&quot;</span> wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;border&quot;</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;wicket:child <span style="color: #66cc66;">/</span>&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></li><li>&nbsp;&nbsp;Base End</li><li><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>wicket:panel&gt;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Die davon abgeleitete Klasse sieht dann wie folgt aus:</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.transparent.lazy</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.MarkupContainer</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.Model</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> SubPanel <span style="color: #000000; font-weight: bold;">extends</span> BasePanel</li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> SubPanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><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;">protected</span> MarkupContainer lazyInit<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;MarkupContainer root = <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">lazyInit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;root.<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;label&quot;</span>,Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sub&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></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">return</span> root<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="HTML"><div class="devcodeoverflow"><ol><li><span style="color: #009900;">&lt;wicket:extend&gt;</span></li><li>&nbsp;&nbsp;<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;label&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></li><li><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>wicket:extend&gt;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Wie man sehen kann, wurde in diesem Beispiel sowohl Markup- als auch Komponentenvererbung benutzt. Trotzdem konnte auf den Einsatz von TransparentResolver verzichtet werden. Die Komponentenhierarchie entspricht der im Markup.</p>
<p>Ich hätte nicht gedacht, dass die Lösung so nahe liegt. Feedback wie immer willkommen&#8230;</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%2F2010%2F01%2F20%2Fwicket-no-transparentresolver%2F&amp;title=Wicket%20-%20No%20TransparentResolver&amp;bodytext=Wie%20ich%20im%20letzten%20Beitrag%20bereits%20angk%C3%BCndigt%20habe%2C%20kann%20man%20tats%C3%A4chlich%20das%20TransparentResolver-Problem%20mit%20Hilfe%20der%20verz%C3%B6gerten%20Initialisierung%20l%C3%B6sen.%20Dazu%20muss%20die%20AbstractLazyPanel-Klasse%20nur%20ein%20wenig%20ver%C3%A4ndert%20werden.%0D%0A%0D%0Apackage%20de.wicket" 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%2F2010%2F01%2F20%2Fwicket-no-transparentresolver%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%2F2010%2F01%2F20%2Fwicket-no-transparentresolver%2F&amp;title=Wicket%20-%20No%20TransparentResolver&amp;notes=Wie%20ich%20im%20letzten%20Beitrag%20bereits%20angk%C3%BCndigt%20habe%2C%20kann%20man%20tats%C3%A4chlich%20das%20TransparentResolver-Problem%20mit%20Hilfe%20der%20verz%C3%B6gerten%20Initialisierung%20l%C3%B6sen.%20Dazu%20muss%20die%20AbstractLazyPanel-Klasse%20nur%20ein%20wenig%20ver%C3%A4ndert%20werden.%0D%0A%0D%0Apackage%20de.wicket" 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%2F2010%2F01%2F20%2Fwicket-no-transparentresolver%2F&amp;t=Wicket%20-%20No%20TransparentResolver" 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%2F2010%2F01%2F20%2Fwicket-no-transparentresolver%2F&amp;title=Wicket%20-%20No%20TransparentResolver" 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%2F2010%2F01%2F20%2Fwicket-no-transparentresolver%2F&amp;title=Wicket%20-%20No%20TransparentResolver&amp;annotation=Wie%20ich%20im%20letzten%20Beitrag%20bereits%20angk%C3%BCndigt%20habe%2C%20kann%20man%20tats%C3%A4chlich%20das%20TransparentResolver-Problem%20mit%20Hilfe%20der%20verz%C3%B6gerten%20Initialisierung%20l%C3%B6sen.%20Dazu%20muss%20die%20AbstractLazyPanel-Klasse%20nur%20ein%20wenig%20ver%C3%A4ndert%20werden.%0D%0A%0D%0Apackage%20de.wicket" 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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>20. Januar 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/01/20/wicket-lazy-init/" title="Wicket &#8211; verzögerte Initialisierung">Wicket &#8211; verzögerte Initialisierung</a></li><li>15. Juli 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/07/15/wicket-flexibilitat-mit-factories/" title="Wicket &#8211; Flexibilität mit Factories">Wicket &#8211; Flexibilität mit Factories</a></li><li>14. April 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/04/14/wicket-eclipse-plugin-qwickie/" title="Wicket Eclipse Plugin &#8211;  qwickie">Wicket Eclipse Plugin &#8211;  qwickie</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2010/01/20/wicket-no-transparentresolver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wicket &#8211; verzögerte Initialisierung</title>
		<link>http://www.wicket-praxis.de/blog/2010/01/20/wicket-lazy-init/</link>
		<comments>http://www.wicket-praxis.de/blog/2010/01/20/wicket-lazy-init/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 08:28:05 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[init]]></category>
		<category><![CDATA[lazy]]></category>
		<category><![CDATA[transparent resolver]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=237</guid>
		<description><![CDATA[Nicht immer ist es möglich oder sinnvoll, im Konstruktor einer Komponente bereits die vollständige Komponentenstruktur anzulegen. Wie man Komponenten zu einem späteren Zeitpunkt anlegen kann, kann man in den Repeater-Klassen ansehen. Aber es geht wesentlich einfacher. Nach dem Erstellen einer Komponente wird als nächstes (für den Fall,dass die Komponente dargestellt wird) onBeforeRender() aufgerufen. Wir können [...]]]></description>
			<content:encoded><![CDATA[<p>Nicht immer ist es möglich oder sinnvoll, im Konstruktor einer Komponente bereits die vollständige Komponentenstruktur anzulegen. Wie man Komponenten zu einem späteren Zeitpunkt anlegen kann, kann man in den Repeater-Klassen ansehen. Aber es geht wesentlich einfacher. Nach dem Erstellen einer Komponente wird als nächstes (für den Fall,dass die Komponente dargestellt wird) onBeforeRender() aufgerufen. Wir können die fehlenden Komponenten in diesem Methodenaufruf erstellen. Wir müssen nur darauf achten, dass diese Initialisierung nur einmal durchgeführt wird. Am besten verpacken wir das ganze in eine eigene Klasse.</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.lazy</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.panel.Panel</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;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> AbstractLazyPanel <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Panel</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #006600; font-weight: bold;">boolean</span> _lazyInitCalled<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> AbstractLazyPanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><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;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> onBeforeRender<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;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>_lazyInitCalled<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;_lazyInitCalled=<span style="color: #006600; font-weight: bold;">true</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lazyInit<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;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onBeforeRender</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>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #006600; font-weight: bold;">void</span> lazyInit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Eigene Komponenten werden dann von dieser Klasse abgeleitet. Dieser Umbau hat keine Veränderung des Markup zur Folge, da keinerlei Hilfskomponenten eingefügt wurden.</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.lazy</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.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.Model</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> TestPanel <span style="color: #000000; font-weight: bold;">extends</span> AbstractLazyPanel</li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> TestPanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><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;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> lazyInit<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;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;label&quot;</span>,Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Label&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></li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SimplePanel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;panel&quot;</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></ol></div></pre><!--END_DEVFMTCODE--></p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="HTML"><div class="devcodeoverflow"><ol><li><span style="color: #009900;">&lt;wicket:panel&gt;</span></li><li>&nbsp;&nbsp;<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;label&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: #000000; font-weight: bold;">br</span>&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;wicket:container wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;panel&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>wicket:container&gt;</span></li><li><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>wicket:panel&gt;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Wie man sieht, lässt sich die neuen Klasse sehr einfach als Ersatz für die Panel-Klasse benutzen. Vielleicht ist dieser Ansatz ausbaufähig, so dass man durch eine verspätete Initialisierung auch die Probleme rund um TransparentResolver umgehen kann.</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%2F2010%2F01%2F20%2Fwicket-lazy-init%2F&amp;title=Wicket%20-%20verz%C3%B6gerte%20Initialisierung&amp;bodytext=Nicht%20immer%20ist%20es%20m%C3%B6glich%20oder%20sinnvoll%2C%20im%20Konstruktor%20einer%20Komponente%20bereits%20die%20vollst%C3%A4ndige%20Komponentenstruktur%20anzulegen.%20Wie%20man%20Komponenten%20zu%20einem%20sp%C3%A4teren%20Zeitpunkt%20anlegen%20kann%2C%20kann%20man%20in%20den%20Repeater-Klassen%20ansehen.%20Aber%20es%20geht%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%2F2010%2F01%2F20%2Fwicket-lazy-init%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%2F2010%2F01%2F20%2Fwicket-lazy-init%2F&amp;title=Wicket%20-%20verz%C3%B6gerte%20Initialisierung&amp;notes=Nicht%20immer%20ist%20es%20m%C3%B6glich%20oder%20sinnvoll%2C%20im%20Konstruktor%20einer%20Komponente%20bereits%20die%20vollst%C3%A4ndige%20Komponentenstruktur%20anzulegen.%20Wie%20man%20Komponenten%20zu%20einem%20sp%C3%A4teren%20Zeitpunkt%20anlegen%20kann%2C%20kann%20man%20in%20den%20Repeater-Klassen%20ansehen.%20Aber%20es%20geht%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%2F2010%2F01%2F20%2Fwicket-lazy-init%2F&amp;t=Wicket%20-%20verz%C3%B6gerte%20Initialisierung" 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%2F2010%2F01%2F20%2Fwicket-lazy-init%2F&amp;title=Wicket%20-%20verz%C3%B6gerte%20Initialisierung" 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%2F2010%2F01%2F20%2Fwicket-lazy-init%2F&amp;title=Wicket%20-%20verz%C3%B6gerte%20Initialisierung&amp;annotation=Nicht%20immer%20ist%20es%20m%C3%B6glich%20oder%20sinnvoll%2C%20im%20Konstruktor%20einer%20Komponente%20bereits%20die%20vollst%C3%A4ndige%20Komponentenstruktur%20anzulegen.%20Wie%20man%20Komponenten%20zu%20einem%20sp%C3%A4teren%20Zeitpunkt%20anlegen%20kann%2C%20kann%20man%20in%20den%20Repeater-Klassen%20ansehen.%20Aber%20es%20geht%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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>20. Januar 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/01/20/wicket-no-transparentresolver/" title="Wicket &#8211; No TransparentResolver">Wicket &#8211; No TransparentResolver</a></li><li>15. Juli 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/07/15/wicket-flexibilitat-mit-factories/" title="Wicket &#8211; Flexibilität mit Factories">Wicket &#8211; Flexibilität mit Factories</a></li><li>14. April 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/04/14/wicket-eclipse-plugin-qwickie/" title="Wicket Eclipse Plugin &#8211;  qwickie">Wicket Eclipse Plugin &#8211;  qwickie</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2010/01/20/wicket-lazy-init/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Wicket &#8211; lose Koppelung von Komponenten</title>
		<link>http://www.wicket-praxis.de/blog/2010/01/05/wicket-lose-koppelung-von-komponenten/</link>
		<comments>http://www.wicket-praxis.de/blog/2010/01/05/wicket-lose-koppelung-von-komponenten/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 08:02:40 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[coupling]]></category>
		<category><![CDATA[koppelung]]></category>
		<category><![CDATA[loose]]></category>
		<category><![CDATA[lose]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=225</guid>
		<description><![CDATA[Auch bei Webanwendungen entstehen schnell komplexe Oberflächen. Es ist nur eine Frage der Zeit, bis man Komponenten, die miteinander interagieren sollen, gegenseitig bekannt macht. Diese Vorgehensweise ist limitiert und außerdem sehr aufwendig. Wie ich bereits im Buch beschrieben habe, kann man die Koppelung von Komponenten aufweichen, die per Ajax neu gezeichnet werden müssen. Dabei ist [...]]]></description>
			<content:encoded><![CDATA[<p>Auch bei Webanwendungen entstehen schnell komplexe Oberflächen. Es ist nur eine Frage der Zeit, bis man Komponenten, die miteinander interagieren sollen, gegenseitig bekannt macht. Diese Vorgehensweise ist limitiert und außerdem sehr aufwendig. Wie ich bereits im <a href="http://books.google.de/books?id=9esdx8R-fJAC&#038;pg=PA103&#038;lpg=PA103&#038;dq=praxisbuch+wicket+Ajax+Events&#038;source=bl&#038;ots=ajlFEqWKuj&#038;sig=FA36Ar-X7aa4psPGuECpIJrKZtU&#038;hl=de&#038;ei=aONCS6-AFZLcmgOI4azzCw&#038;sa=X&#038;oi=book_result&#038;ct=result&#038;resnum=10&#038;ved=0CDQQ6AEwCQ#v=onepage&#038;q=&#038;f=false">Buch</a> beschrieben habe, kann man die Koppelung von Komponenten aufweichen, die per Ajax neu gezeichnet werden müssen. Dabei ist es zu kurz gedacht, dass man die Entkoppelung von Komponenten nur aus diesem Grund forciert.</p>
<p>Der Unterschied zwischen einem normalen Request und einem Ajax-Request liegt darin, dass bei einem Ajax-Request nur Teile der Seite neu gerendert werden. Dazu müssen die Komponenten markiert werden, die in der Zielseite ersetzt werden sollen. Wenn es sich um einen normalen Request handelt, ist das nicht notwendig, da die ganze Seite und damit alle Komponenten neu gerendert werden.</p>
<p>Solange sich alle Aktionen auf die Änderungen von Daten beziehen, die dann entweder per Ajax neu dargestellt werden oder beim Darstellen der ganzen Seite automatisch angezeigt werden, besteht eigentlich kein Grund, mehr Aufwand in das Entkoppeln von Komponenten zu stecken. Doch oft ist das Ändern der Daten nicht trivial, der Code verteilt sich unwillkürlich auf verschiedene Komponenten.</p>
<p>Um dieser Entwicklung entgegen zu wirken, erweitert man das Event-Konzept einfach auch auf normale Requests. Im folgenden Code werden daher alle notwendigen Klassen aufgeführt. Die im Buch verwendeten Klassen können durch diese ersetzt werden.</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.events</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> EventListenerInterface</li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> notifyAjaxEvent<span style="color: #009900;">&#40;</span>AbstractEvent event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Das EventListenerInterface muss jede Komponente implementieren, dass auf Events reagieren muss.</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.events</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.Component</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.Page</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.Component.IVisitor</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.AjaxRequestTarget</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> AbstractEvent</li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #003399; font-weight: bold;">Component</span> _source<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;AjaxRequestTarget _requestTarget<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> AbstractEvent<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Component</span> source,AjaxRequestTarget requestTarget<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_source=source<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_requestTarget=requestTarget<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: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Component</span> getSource<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;">return</span> _source<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: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> fire<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;Page page = _source.<span style="color: #006633;">getPage</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;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>page <span style="color: #000000; font-weight: bold;">instanceof</span> EventListenerInterface<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: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>EventListenerInterface<span style="color: #009900;">&#41;</span> page<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">notifyAjaxEvent</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: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;page.<span style="color: #006633;">visitChildren</span><span style="color: #009900;">&#40;</span>EventListenerInterface.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000000; font-weight: bold;">new</span> AjaxEventVisitor<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></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: #006600; font-weight: bold;">void</span> update<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Component</span> component<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;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_requestTarget<span style="color: #339933;">!</span>=<span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> _requestTarget.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>component<span style="color: #009900;">&#41;</span><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: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> AjaxEventVisitor <span style="color: #000000; font-weight: bold;">implements</span> IVisitor<span style="color: #339933;">&lt;</span>Component<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;AbstractEvent _event<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> AjaxEventVisitor<span style="color: #009900;">&#40;</span>AbstractEvent event<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;_event=event<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;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Object</span> component<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Component</span> component<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: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>EventListenerInterface<span style="color: #009900;">&#41;</span> component<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">notifyAjaxEvent</span><span style="color: #009900;">&#40;</span>_event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">return</span> IVisitor.<span style="color: #006633;">CONTINUE_TRAVERSAL</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><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Die Eventklasse wurde dahingehend erweitert, dass jetzt auch für die Seite geprüft wird, ob das EventListernerInterface implementiert wurde. Ob Ajax benutzt wurde oder nicht, wird in der update()-Methode überprüft, so dass man diese Prüfung nicht mehr selbst vornehmen muss.</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.events</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.Component</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.AjaxRequestTarget</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> <span style="color: #003399; font-weight: bold;">ChangeEvent</span> <span style="color: #000000; font-weight: bold;">extends</span> AbstractEvent</li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #006600; font-weight: bold;">int</span> _change<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399; font-weight: bold;">ChangeEvent</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Component</span> source, AjaxRequestTarget requestTarget, <span style="color: #006600; font-weight: bold;">int</span> change<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;">super</span><span style="color: #009900;">&#40;</span>source, requestTarget<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;_change=change<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: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">int</span> getChange<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;">return</span> _change<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Der ChangeEvent wurde abgeleitet und um eine Information erweitert. In der folgenden Komponente wird diese Information ausgewertet:</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.events</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.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.panel.Panel</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> CounterPanel <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Panel</span> <span style="color: #000000; font-weight: bold;">implements</span> EventListenerInterface</li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> _counter<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> CounterPanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id,IModel<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> counter<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;setOutputMarkupId<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;_counter=counter<span style="color: #339933;">;</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;counter&quot;</span>,_counter<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>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> notifyAjaxEvent<span style="color: #009900;">&#40;</span>AbstractEvent event<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;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>event <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399; font-weight: bold;">ChangeEvent</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: #006600; font-weight: bold;">int</span> change = <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">ChangeEvent</span><span style="color: #009900;">&#41;</span> event<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getChange</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: #003399; font-weight: bold;">Integer</span> cur = _counter.<span style="color: #006633;">getObject</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;&nbsp;&nbsp;&nbsp;&nbsp;info<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Aktuell: &quot;</span>+cur+<span style="color: #0000ff;">&quot; Change: &quot;</span>+change<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_counter.<span style="color: #006633;">setObject</span><span style="color: #009900;">&#40;</span>cur+change<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;event.<span style="color: #006633;">update</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: #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><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Man beachte, dass für die Komponente setOutputMarkupId() aufgerufen wird, da diese Komponente evtl. per Ajax aktualisiert werden kann.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="HTML"><div class="devcodeoverflow"><ol><li><span style="color: #009900;">&lt;wicket:panel&gt;</span></li><li>&nbsp;&nbsp;<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;counter&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></li><li><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>wicket:panel&gt;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Jetzt benötigen wir noch eine Komponente, die diesen Event auslöst:</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.events</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.ajax.AjaxRequestTarget</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.markup.html.AjaxFallbackLink</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.panel.Panel</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> ActionPanel <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Panel</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> ActionPanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id,IModel<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> change<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;AjaxFallbackLink<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> link = <span style="color: #000000; font-weight: bold;">new</span> AjaxFallbackLink<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span>,change<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;">public</span> <span style="color: #006600; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span>AjaxRequestTarget target<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;">new</span> <span style="color: #003399; font-weight: bold;">ChangeEvent</span><span style="color: #009900;">&#40;</span>ActionPanel.<span style="color: #000000; font-weight: bold;">this</span>,target,getModelObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">fire</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;&nbsp;&nbsp;&nbsp;link.<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;change&quot;</span>,change<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>link<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></ol></div></pre><!--END_DEVFMTCODE--></p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="HTML"><div class="devcodeoverflow"><ol><li><span style="color: #009900;">&lt;wicket:panel&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;link&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;change&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;">a</span>&gt;</span></li><li><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>wicket:panel&gt;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Nachdem wir alle Komponten erstell habe, benutzen wir sie in einer Anwendung:</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.events</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.panel.FeedbackPanel</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>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EventPage <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> EventPage<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;add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> EventFeedbackPanel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;feedback&quot;</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;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ActionPanel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;changeAdd1&quot;</span>,Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span>1<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;add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ActionPanel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;changeSub1&quot;</span>,Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span>-1<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;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CounterPanel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;counter&quot;</span>,Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span>5<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;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> EventFeedbackPanel <span style="color: #000000; font-weight: bold;">extends</span> FeedbackPanel <span style="color: #000000; font-weight: bold;">implements</span> EventListenerInterface</li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> EventFeedbackPanel<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> id<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;">super</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setOutputMarkupId<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">true</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;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> notifyAjaxEvent<span style="color: #009900;">&#40;</span>AbstractEvent event<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;event.<span style="color: #006633;">update</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: #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><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Wie man sieht, habe ich auch ein FeedbackPanel erstellt, dass auf Events (und in diesem Fall jedes) reagiert.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Java(TM) 2 Platform Standard Edition 5.0"><div class="devcodeoverflow"><ol><li><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>EventPage<span style="color: #339933;">&lt;</span>/title<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #339933;">&lt;</span>/head<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #339933;">&lt;</span>div wicket:id=<span style="color: #0000ff;">&quot;feedback&quot;</span><span style="color: #339933;">&gt;&lt;</span>/div<span style="color: #339933;">&gt;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #339933;">&lt;</span>wicket:container wicket:id=<span style="color: #0000ff;">&quot;changeAdd1&quot;</span><span style="color: #339933;">&gt;&lt;</span>/wicket:container<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #339933;">&lt;</span>wicket:container wicket:id=<span style="color: #0000ff;">&quot;changeSub1&quot;</span><span style="color: #339933;">&gt;&lt;</span>/wicket:container<span style="color: #339933;">&gt;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #339933;">&lt;</span>div wicket:id=<span style="color: #0000ff;">&quot;counter&quot;</span><span style="color: #339933;">&gt;&lt;</span>/div<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #339933;">&lt;</span>/body<span style="color: #339933;">&gt;</span></li><li><span style="color: #339933;">&lt;</span>/html<span style="color: #339933;">&gt;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Wenn Komponenten per Ajax aktualisiert werden müssen, funktioniert das nur, wenn es auch ein Html-Tag mit der passenden ID gibt, dass per Javascript gefunden und ersetzt werden kann. Daher muss man die Komponente dann an ein Html-Tag binden, die Einbettung über wicket:container funktioniert nicht.</p>
<p>Betätigt man nun einen der Links in der AktionPanel-Komponente, dann wird der Zähler in der CounterPanel-Komponenten angepasst und eine entsprechende Meldung im FeedbackPanel angezeigt. Wenn man nun das CounterPanel einfach ausbaut, passiert nichts. Das zeigt zum einen, dass die Komponenten wirklich unabhängig voneinander sind, zum anderen aber auch, welches Risiko man eingeht: es kann vorkommen, dass Events nicht verarbeitet werden.</p>
<p>Dieses Beispiel veranschaulicht, wie einfach man Komponenten entkoppeln kann. Doch dieses Beispiel ist nur eine einfache Anwendung. Wie weit man diese Vorgehensweise in der Praxis treiben kann, möchte ich in ein paar Sichtpunkten erwähnen:</p>
<ul>
<li>Anwendung der Möglichkeiten von Vererbung auf Events</li>
<li>Prüfung, ob ein Event einen Empfänger erreicht hat</li>
<li>Kaskadierung von Events (wenn Event A eintrifft, wird Event B ausgelöst)</li>
<li>Mehr als ein Sender und mehr als einen Empfänger für Events</li>
<li>Ein Event kann mit und ohne Ajax ausgelöst werden, ohne dass der Code auf Empfängerseite angepasst werden muss.</li>
</ul>
<p>Ich hoffe, dass dient als Anregung oder Vorlage. Komplexen Oberflächen mit Wicket steht nun nichts mehr im Weg.</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%2F2010%2F01%2F05%2Fwicket-lose-koppelung-von-komponenten%2F&amp;title=Wicket%20-%20lose%20Koppelung%20von%20Komponenten&amp;bodytext=Auch%20bei%20Webanwendungen%20entstehen%20schnell%20komplexe%20Oberfl%C3%A4chen.%20Es%20ist%20nur%20eine%20Frage%20der%20Zeit%2C%20bis%20man%20Komponenten%2C%20die%20miteinander%20interagieren%20sollen%2C%20gegenseitig%20bekannt%20macht.%20Diese%20Vorgehensweise%20ist%20limitiert%20und%20au%C3%9Ferdem%20sehr%20aufwendig.%20Wie" 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%2F2010%2F01%2F05%2Fwicket-lose-koppelung-von-komponenten%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%2F2010%2F01%2F05%2Fwicket-lose-koppelung-von-komponenten%2F&amp;title=Wicket%20-%20lose%20Koppelung%20von%20Komponenten&amp;notes=Auch%20bei%20Webanwendungen%20entstehen%20schnell%20komplexe%20Oberfl%C3%A4chen.%20Es%20ist%20nur%20eine%20Frage%20der%20Zeit%2C%20bis%20man%20Komponenten%2C%20die%20miteinander%20interagieren%20sollen%2C%20gegenseitig%20bekannt%20macht.%20Diese%20Vorgehensweise%20ist%20limitiert%20und%20au%C3%9Ferdem%20sehr%20aufwendig.%20Wie" 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%2F2010%2F01%2F05%2Fwicket-lose-koppelung-von-komponenten%2F&amp;t=Wicket%20-%20lose%20Koppelung%20von%20Komponenten" 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%2F2010%2F01%2F05%2Fwicket-lose-koppelung-von-komponenten%2F&amp;title=Wicket%20-%20lose%20Koppelung%20von%20Komponenten" 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%2F2010%2F01%2F05%2Fwicket-lose-koppelung-von-komponenten%2F&amp;title=Wicket%20-%20lose%20Koppelung%20von%20Komponenten&amp;annotation=Auch%20bei%20Webanwendungen%20entstehen%20schnell%20komplexe%20Oberfl%C3%A4chen.%20Es%20ist%20nur%20eine%20Frage%20der%20Zeit%2C%20bis%20man%20Komponenten%2C%20die%20miteinander%20interagieren%20sollen%2C%20gegenseitig%20bekannt%20macht.%20Diese%20Vorgehensweise%20ist%20limitiert%20und%20au%C3%9Ferdem%20sehr%20aufwendig.%20Wie" 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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>15. Juli 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/07/15/wicket-flexibilitat-mit-factories/" title="Wicket &#8211; Flexibilität mit Factories">Wicket &#8211; Flexibilität mit Factories</a></li><li>16. Oktober 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/10/16/wicket-component-overview/" title="Wicket Komponentenübersicht">Wicket Komponentenübersicht</a></li><li>14. April 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/04/14/wicket-eclipse-plugin-qwickie/" title="Wicket Eclipse Plugin &#8211;  qwickie">Wicket Eclipse Plugin &#8211;  qwickie</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2010/01/05/wicket-lose-koppelung-von-komponenten/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wicket nicht nur für Einsteiger</title>
		<link>http://www.wicket-praxis.de/blog/2009/11/11/wicket-nicht-nur-fur-einsteiger/</link>
		<comments>http://www.wicket-praxis.de/blog/2009/11/11/wicket-nicht-nur-fur-einsteiger/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 08:03:43 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[erfahrung]]></category>
		<category><![CDATA[projekt]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=196</guid>
		<description><![CDATA[Ich durfte an einem Projekt teilhaben, in dem für eine neu zu erstellende Anwendung Wicket eingesetzt wurde. Am Anfang wurde das Projekt entsprechend der Anforderungen aufgesetzt (Maven, Hibernate, Spring, Wicket) und der Rahmen der Anwendung geschaffen (Konfiguration der Datenbank, Unittests, etc.). Nach einer doch recht kurzen Einführung in Wicket wurde die Anwendung ohne fremde Hilfe [...]]]></description>
			<content:encoded><![CDATA[<p>Ich durfte an einem Projekt teilhaben, in dem für eine neu zu erstellende Anwendung Wicket eingesetzt wurde. Am Anfang wurde das Projekt entsprechend der Anforderungen aufgesetzt (Maven, Hibernate, Spring, Wicket) und der Rahmen der Anwendung geschaffen (Konfiguration der Datenbank, Unittests, etc.). Nach einer doch recht kurzen Einführung in Wicket wurde die Anwendung ohne fremde Hilfe (wenn man mal Google mal ausklammert) entwickelt und mit immer mehr Funktionen angereichert. Gestern habe ich mir den aktuellen Stand angesehen und musste feststellen, dass entgegen meinen Erwartungen eine recht vernünftige Anwendung entstanden ist.</p>
<p><strong>Warum habe ich das so nicht erwartet?</strong></p>
<p>In dem Projekt war bisher wenig bis kein Wissen über Java und die benutzten Frameworks vorhanden. In der kurzen Einführung konnten weder die Sprache, noch die verwendeten Technologien ausführlich genug erklärt werden. Das bedeutet normalerweise, dass die Lösungen, die bei solchen Unterfangen entstehen, verschiedenste Defizite aufweisen. Neben der Tatsache, dass die Anwendung funktioniert (sicher gibt es noch irgendwo ein paar Fehler, aber wo gibt es die nicht), ist die Anwendung auch noch in einer ausreichend guten Verfassung, so dass die Struktur verstanden werden konnte und die Anpassungen, die wir durchgeführt haben, nicht dazu führten, dass etwas nicht mehr funktionierte.</p>
<p><strong>Gründe</strong></p>
<p>Ein nicht unwesentlichen Anteil daran, dass das Projekt besser als erwartet funktioniert hat, trägt sicherlich Wicket als Framework. Wenn man die Hürde genommen hat, die das Thema Modelle darstellt, ist der Rest recht offensichtlich. Eigene Komponenten werden erstellt, weil es a) sehr einfach ist und b) (viel entscheidender) man als Entwickler automatisch davon profitiert. Die Übersichtlichkeit der Anwendung entsteht auf diese Weise automatisch.</p>
<p><strong>Fazit</strong></p>
<p>Das eine Anwendung funktioniert, ist mindestens ein Maßstab zur Bewertung. Diese Anforderung ist gerade bei Webanwendungen nicht einfach zu erreichen. In Anbetracht der eher schlechten Voraussetzungen muss man das Ergebnis als gelungen bezeichnen. Da ich gebeten wurde, meine Einschätzung zu diesem Projekt abzugeben, freut es nicht nur mich, sondern sicher auch das Team, dass ich positiv überrascht bin.</p>
<p>Mit welcher anderen Technologie wäre dieses Projekt ähnlich gut verlaufen?</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%2F11%2F11%2Fwicket-nicht-nur-fur-einsteiger%2F&amp;title=Wicket%20nicht%20nur%20f%C3%BCr%20Einsteiger&amp;bodytext=Ich%20durfte%20an%20einem%20Projekt%20teilhaben%2C%20in%20dem%20f%C3%BCr%20eine%20neu%20zu%20erstellende%20Anwendung%20Wicket%20eingesetzt%20wurde.%20Am%20Anfang%20wurde%20das%20Projekt%20entsprechend%20der%20Anforderungen%20aufgesetzt%20%28Maven%2C%20Hibernate%2C%20Spring%2C%20Wicket%29%20und%20der%20Rahmen%20der%20Anwendung%20gescha" 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%2F11%2F11%2Fwicket-nicht-nur-fur-einsteiger%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%2F11%2F11%2Fwicket-nicht-nur-fur-einsteiger%2F&amp;title=Wicket%20nicht%20nur%20f%C3%BCr%20Einsteiger&amp;notes=Ich%20durfte%20an%20einem%20Projekt%20teilhaben%2C%20in%20dem%20f%C3%BCr%20eine%20neu%20zu%20erstellende%20Anwendung%20Wicket%20eingesetzt%20wurde.%20Am%20Anfang%20wurde%20das%20Projekt%20entsprechend%20der%20Anforderungen%20aufgesetzt%20%28Maven%2C%20Hibernate%2C%20Spring%2C%20Wicket%29%20und%20der%20Rahmen%20der%20Anwendung%20gescha" 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%2F11%2F11%2Fwicket-nicht-nur-fur-einsteiger%2F&amp;t=Wicket%20nicht%20nur%20f%C3%BCr%20Einsteiger" 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%2F11%2F11%2Fwicket-nicht-nur-fur-einsteiger%2F&amp;title=Wicket%20nicht%20nur%20f%C3%BCr%20Einsteiger" 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%2F11%2F11%2Fwicket-nicht-nur-fur-einsteiger%2F&amp;title=Wicket%20nicht%20nur%20f%C3%BCr%20Einsteiger&amp;annotation=Ich%20durfte%20an%20einem%20Projekt%20teilhaben%2C%20in%20dem%20f%C3%BCr%20eine%20neu%20zu%20erstellende%20Anwendung%20Wicket%20eingesetzt%20wurde.%20Am%20Anfang%20wurde%20das%20Projekt%20entsprechend%20der%20Anforderungen%20aufgesetzt%20%28Maven%2C%20Hibernate%2C%20Spring%2C%20Wicket%29%20und%20der%20Rahmen%20der%20Anwendung%20gescha" 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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>15. Juli 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/07/15/wicket-flexibilitat-mit-factories/" title="Wicket &#8211; Flexibilität mit Factories">Wicket &#8211; Flexibilität mit Factories</a></li><li>14. April 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/04/14/wicket-eclipse-plugin-qwickie/" title="Wicket Eclipse Plugin &#8211;  qwickie">Wicket Eclipse Plugin &#8211;  qwickie</a></li><li>9. April 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/04/09/wicket-abstractevent-update/" title="Wicket &#8211; AbstractEvent Update">Wicket &#8211; AbstractEvent Update</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2009/11/11/wicket-nicht-nur-fur-einsteiger/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PropertyModel &#8211; einfach ist nicht immer gut</title>
		<link>http://www.wicket-praxis.de/blog/2009/11/04/dont-use-property-model-at-all/</link>
		<comments>http://www.wicket-praxis.de/blog/2009/11/04/dont-use-property-model-at-all/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 07:17:20 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[detached]]></category>
		<category><![CDATA[loadable]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[property]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=192</guid>
		<description><![CDATA[Ich bin kürzlich über ein Stück Code gestolpert, der mich zum nachdenken brachte. Um zu illustrieren, welcher Umstand dafür verantwortlich war, benötige ich diesemal am schon Anfang ein paar Zeilen Code. Die folgende Hilfsklasse dient nur dazu, bei dem einzig möglichen Methodenaufruf eine Liste von Daten zu erzeugen:
package de.wicketpraxis.web.blog.pages.migration.model.property;&#160;import java.io.Serializable;import java.util.Arrays;import java.util.List;&#160;public class Generator implements [...]]]></description>
			<content:encoded><![CDATA[<p>Ich bin kürzlich über ein Stück Code gestolpert, der mich zum nachdenken brachte. Um zu illustrieren, welcher Umstand dafür verantwortlich war, benötige ich diesemal am schon Anfang ein paar Zeilen Code. Die folgende Hilfsklasse dient nur dazu, bei dem einzig möglichen Methodenaufruf eine Liste von Daten zu erzeugen:</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.migration.model.property</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.io.Serializable</span><span style="color: #339933;">;</span></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;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Generator <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399; font-weight: bold;">Serializable</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> findAll<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;">return</span> <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;fun&quot;</span>,<span style="color: #0000ff;">&quot;with&quot;</span>,<span style="color: #0000ff;">&quot;wicket&quot;</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 Generator dient hier als Platzhalter für eine wie auch immer gelagerte Datenschicht.</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.migration.model.property</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><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.model.LoadableDetachableModel</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.model.PropertyModel</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">de.wicketpraxis.wicket.model.Models</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">de.wicketpraxis.wicket.model.transformation.Function1</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> UseOrNotUsePropertyModelPage <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> UseOrNotUsePropertyModelPage<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;">final</span> Generator gen=<span style="color: #000000; font-weight: bold;">new</span> Generator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;&gt;</span> model = <span style="color: #000000; font-weight: bold;">new</span> LoadableDetachableModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;&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;">protected</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> load<span style="color: #009900;">&#40;</span><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;">return</span> gen.<span style="color: #006633;">findAll</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><span style="color: #339933;">;</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;model=<span style="color: #000000; font-weight: bold;">new</span> PropertyModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span>gen,<span style="color: #0000ff;">&quot;findAll&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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> ListView<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;list&quot;</span>,model<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>String<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;value&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>Da es nicht meine Art ist, unvollständigen Code abzubilden, kommt auch hier erst das Markup und dann die Erklärung:</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>PropertyModel Usage Page<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;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Liste<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&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;value&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>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</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><strong>Was ist an diesem Beispiel bemerkenswert?</strong></p>
<p>Am Anfang erzeuge ich ein Model über eine LoadableDetachableModel-Implementierung, die die Daten aus dem Methodenaufruf zurück gibt. Das ist nichts neues und wurde bereits oft behandelt. Diese Model-Instanz wird in der folgenden Zeile mit einer PropertyModel-Instanz überschrieben. Es ist unstrittig, dass dieser Ansatz funktioniert. Die Methode wird per Reflection aufgerufen und die Werte werden per getObject() zurückgeliefert. Doch wo liegt das Problem?</p>
<p><strong>Refactoring</strong></p>
<p>Die Zeile Code, die man erhält, wenn man das PropertyModel benutzt und die Methode aufzurufen ist angenehm kurz. Aber diese Kürze gibt es nicht umsonst, sondern man muss dafür zahlen. In Bezug auf das Thema Refactoring sogar zwei mal. Das erste Problem ist offensichtlich: Wenn sich der Methodenname ändert (oder Parameter hinzukommen) wird der Aufruf per Reflection nicht mehr funktionierten (oder sogar eine falsche Methode aufrufen), und man erhält zur Laufzeit eine Fehlermeldung.</p>
<p>Der zweite Punkt ist weniger offensichtlich, aber vielleicht noch schwer wiegender, weil zur Laufzeit der Fehler an einer anderen Stelle zu Tage tritt: Der Rückgabewert der Methode wird angepasst. Der Fehler würde in unserem Fall dann vermutlich nur in der Darstellung der ListView auftreten, so dass statt &#8220;fun with wicket&#8221; möglicherweise &#8220;SomeData@65b778 SomeData@32ac12&#8243; angezeigt wird. Es kommt also noch nicht mal zu einem Laufzeitfehler.</p>
<p><strong>Performance</strong></p>
<p>In einem anderen Bereich (der in unserem Beispiel nebensächlich ist) funktioniert die PropertyModel-Variante nicht wie erwartet. Wenn die Methode getObject() aufgerufen wird, wird immer die entsprechende Methode per Reflection aufgerufen. Das bedeutet, die Ergebnisse werden nicht wie beim LoadableDetachedModel zwischengespeichert. Würde ich das Model an zwei ListView-Komponenten binden, würde die Liste zweimal erzeugt werden. Je nach Aufwand der Erzeugung ist das ein eher unerwünschtes Ergebnis. Außerdem kann es natürlich dazu kommen, dass sich die jeweiligen Rückgabewerte unterscheiden, so dass der Nutzer im Zweifel inkonsistente Daten angezeigt bekommt.</p>
<p><strong>Das PropertyModel ist nützlich</strong></p>
<p>Man sollte nach dem Lesen der Zeilen die Verwendung des PropertyModel nicht verbieten, denn Aufwand und Nutzen sind für die Entstehung dieser Model-Klasse verantwortlich. Um die Eingaben aus einem Formularfeld in einem Attribut einer JavaBean zu speichern sollte man das PropertyModel einsetzen, weil der Mehraufwand für eine typsichere (und damit durch normale Refactoring-Operationen greifbare) Variante enorm hoch ist. Ich würde mir wünschen, das Java Sprachmittel bereitstellt, die es ermöglicht, Methoden nicht nur per Reflection zu ermitteln, so dass man gerade für diesen Fall kompakten und trotzdem typsicheren Code schreiben kann. Bis dahin sollte man diese Model-Klasse überlegt verwenden, dann kann eigentlich gar nicht soviel schief gehen.</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%2F11%2F04%2Fdont-use-property-model-at-all%2F&amp;title=PropertyModel%20-%20einfach%20ist%20nicht%20immer%20gut&amp;bodytext=Ich%20bin%20k%C3%BCrzlich%20%C3%BCber%20ein%20St%C3%BCck%20Code%20gestolpert%2C%20der%20mich%20zum%20nachdenken%20brachte.%20Um%20zu%20illustrieren%2C%20welcher%20Umstand%20daf%C3%BCr%20verantwortlich%20war%2C%20ben%C3%B6tige%20ich%20diesemal%20am%20schon%20Anfang%20ein%20paar%20Zeilen%20Code.%20Die%20folgende%20Hilfsklasse%20dient%20nur%20dazu%2C%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%2F11%2F04%2Fdont-use-property-model-at-all%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%2F11%2F04%2Fdont-use-property-model-at-all%2F&amp;title=PropertyModel%20-%20einfach%20ist%20nicht%20immer%20gut&amp;notes=Ich%20bin%20k%C3%BCrzlich%20%C3%BCber%20ein%20St%C3%BCck%20Code%20gestolpert%2C%20der%20mich%20zum%20nachdenken%20brachte.%20Um%20zu%20illustrieren%2C%20welcher%20Umstand%20daf%C3%BCr%20verantwortlich%20war%2C%20ben%C3%B6tige%20ich%20diesemal%20am%20schon%20Anfang%20ein%20paar%20Zeilen%20Code.%20Die%20folgende%20Hilfsklasse%20dient%20nur%20dazu%2C%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%2F11%2F04%2Fdont-use-property-model-at-all%2F&amp;t=PropertyModel%20-%20einfach%20ist%20nicht%20immer%20gut" 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%2F11%2F04%2Fdont-use-property-model-at-all%2F&amp;title=PropertyModel%20-%20einfach%20ist%20nicht%20immer%20gut" 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%2F11%2F04%2Fdont-use-property-model-at-all%2F&amp;title=PropertyModel%20-%20einfach%20ist%20nicht%20immer%20gut&amp;annotation=Ich%20bin%20k%C3%BCrzlich%20%C3%BCber%20ein%20St%C3%BCck%20Code%20gestolpert%2C%20der%20mich%20zum%20nachdenken%20brachte.%20Um%20zu%20illustrieren%2C%20welcher%20Umstand%20daf%C3%BCr%20verantwortlich%20war%2C%20ben%C3%B6tige%20ich%20diesemal%20am%20schon%20Anfang%20ein%20paar%20Zeilen%20Code.%20Die%20folgende%20Hilfsklasse%20dient%20nur%20dazu%2C%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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>28. Oktober 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/10/28/wicket-model-transformation/" title="Wicket Model Transformation">Wicket Model Transformation</a></li><li>16. Oktober 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/10/16/wicket-component-overview/" title="Wicket Komponentenübersicht">Wicket Komponentenübersicht</a></li><li>22. September 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/09/22/migration-zu-wicket-model/" title="Migration zu Wicket: Model">Migration zu Wicket: Model</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2009/11/04/dont-use-property-model-at-all/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wicket Model Transformation</title>
		<link>http://www.wicket-praxis.de/blog/2009/10/28/wicket-model-transformation/</link>
		<comments>http://www.wicket-praxis.de/blog/2009/10/28/wicket-model-transformation/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 06:11:48 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[detach]]></category>
		<category><![CDATA[loadableDetachedModel]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[referenzen]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=175</guid>
		<description><![CDATA[Eine Liste von Ergebnissen aus einer Tabelle in der Datenbank zu laden und über ein Model zur Verfügung zu stellen, ist eine recht einfache Angelegenheit. Wicket sorgt dafür, dass die Liste kein zweites mal geladen wird, nur weil das Model durch eine zweite Komponente dargestellt wird. Wenn man z.B. so triviale Dinge wie die Summe [...]]]></description>
			<content:encoded><![CDATA[<p>Eine Liste von Ergebnissen aus einer Tabelle in der Datenbank zu laden und über ein Model zur Verfügung zu stellen, ist eine recht einfache Angelegenheit. Wicket sorgt dafür, dass die Liste kein zweites mal geladen wird, nur weil das Model durch eine zweite Komponente dargestellt wird. Wenn man z.B. so triviale Dinge wie die Summe aller angezeigten Einträge ermitteln möchte, empfiehlt es sich, auf die bereits geladenen Daten aus dem Model zurückzugreifen. Für diesen Zweck kann man auf eine <a href="http://www.wicket-praxis.de/blog/2009/01/03/modell-referenzen/">spezialisierte Model-Klasse</a> zurückgreifen, die sich darum kümmert, das die detach()-Methode auch für alle referenzierten Modelle aufgerufen wird. Der Ansatz ist recht einfach, aber es geht vielleicht noch ein wenig eleganter.</p>
<p><strong>Die Transformation</strong></p>
<p>Als erstes definieren wir Klassen, die für die Transformation sorgen. Da in unserem Beispiel nicht nur ein Model, sondern auch zwei oder drei Model-Referenzen benutzt werden und damit bis zu drei Parametern übergeben werden können, müssen wir auch drei unterschiedliche Schnittstellen definieren:</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.wicket.model.transformation</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.io.Serializable</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> Function1<span style="color: #339933;">&lt;</span>T,M1<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Serializable</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> T apply<span style="color: #009900;">&#40;</span>M1 value<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.wicket.model.transformation</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.io.Serializable</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> Function2<span style="color: #339933;">&lt;</span>T,M1,M2<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Serializable</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> T apply<span style="color: #009900;">&#40;</span>M1 value,M2 value2<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.wicket.model.transformation</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.io.Serializable</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> Function3<span style="color: #339933;">&lt;</span>T,M1,M2,M3<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399; font-weight: bold;">Serializable</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> T apply<span style="color: #009900;">&#40;</span>M1 value,M2 value2, M3 value3<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>Da die verschiedenen Modelle auch verschiedene Daten bereitstellen können, kann jeder Parameter einen eigenen Typ annehmen. Jetzt benötigen wir ein Model, dass die Daten der referenzierten Modelle lädt und der Funktion übergibt und sich das Ergebnis bis zum Aufruf von detach() merkt.</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.wicket.model.transformation</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.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.LoadableDetachableModel</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;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> Transformator<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> LoadableDetachableModel<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;?&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> _subModels<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> Transformator<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;?&gt;</span> ... <span style="color: #006633;">subModels</span><span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_subModels=subModels<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;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> onDetach<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;&nbsp;&nbsp;font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;?&gt;</span> m : _subModels<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;m.<span style="color: #006633;">detach</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;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Model1<span style="color: #339933;">&lt;</span>T,M1<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> Transformator<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> _m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;Function1<span style="color: #339933;">&lt;</span>T, M1<span style="color: #339933;">&gt;</span> _function<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> Model1<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> m1, Function1<span style="color: #339933;">&lt;</span>T, M1<span style="color: #339933;">&gt;</span> function<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;">super</span><span style="color: #009900;">&#40;</span>m1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_m1=m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_function=function<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;@<span style="color: #003399; font-weight: bold;">Override</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> T load<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;">return</span> _function.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>_m1.<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: #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: #000000; font-weight: bold;">class</span> Model2<span style="color: #339933;">&lt;</span>T,M1,M2<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> Transformator<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> _m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> _m2<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;Function2<span style="color: #339933;">&lt;</span>T, M1, M2<span style="color: #339933;">&gt;</span> _function<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> Model2<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> m1, IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> m2, Function2<span style="color: #339933;">&lt;</span>T, M1, M2<span style="color: #339933;">&gt;</span> function<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;">super</span><span style="color: #009900;">&#40;</span>m1,m2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_m1=m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_m2=m2<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_function=function<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;@<span style="color: #003399; font-weight: bold;">Override</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> T load<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;">return</span> _function.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>_m1.<span style="color: #006633;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,_m2.<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: #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: #000000; font-weight: bold;">class</span> Model3<span style="color: #339933;">&lt;</span>T,M1,M2,M3<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> Transformator<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> _m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> _m2<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M3<span style="color: #339933;">&gt;</span> _m3<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;Function3<span style="color: #339933;">&lt;</span>T, M1, M2, M3<span style="color: #339933;">&gt;</span> _function<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> Model3<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> m1, IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> m2, IModel<span style="color: #339933;">&lt;</span>M3<span style="color: #339933;">&gt;</span> m3, Function3<span style="color: #339933;">&lt;</span>T, M1, M2, M3<span style="color: #339933;">&gt;</span> function<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;">super</span><span style="color: #009900;">&#40;</span>m1,m2,m3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_m1=m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_m2=m2<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_m3=m3<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_function=function<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;@<span style="color: #003399; font-weight: bold;">Override</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> T load<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;">return</span> _function.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>_m1.<span style="color: #006633;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,_m2.<span style="color: #006633;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,_m3.<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: #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><span style="color: #009900;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Das war jetzt ein größerer Block, der aber eigentlich nur aus 3 fast gleichen Klassendefinitionen bestand, die leider nicht viel besser zusammenzuführen sind. Wichtig ist dabei die Übergabe aller Model-Referenzen an die Basisklasse, die sich in der onDetach()-Methode (die von der detach()-Methode nur aufgerufen wird, wenn für das Model noch nicht detach() aufgerufen wurde) um das Aufrufen der detach()-Methode dieser Modelle kümmert.</p>
<p>Noch ist dieses ganze Konstrukt nicht viel besser handhabbar als die bisher favorisierte Lösung. Wir benötigen daher noch ein paar Hilfsklassen.</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.wicket.model.transformation</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.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;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> ModelSet</li><li><span style="color: #009900;">&#123;</span></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: #000000; font-weight: bold;">class</span> Set1<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> _m1<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> Set1<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> m1<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;_m1=m1<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;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> IModel<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> apply<span style="color: #009900;">&#40;</span>Function1<span style="color: #339933;">&lt;</span>T, M1<span style="color: #339933;">&gt;</span> function<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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Transformator.<span style="color: #006633;">Model1</span><span style="color: #339933;">&lt;</span>T, M1<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>_m1,function<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;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Set2<span style="color: #339933;">&lt;</span>M1,M2<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> _m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> _m2<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> Set2<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> m1,IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> m2<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;_m1=m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_m2=m2<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;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> IModel<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> apply<span style="color: #009900;">&#40;</span>Function2<span style="color: #339933;">&lt;</span>T, M1, M2<span style="color: #339933;">&gt;</span> function<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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Transformator.<span style="color: #006633;">Model2</span><span style="color: #339933;">&lt;</span>T, M1, M2<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>_m1,_m2,function<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;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Set3<span style="color: #339933;">&lt;</span>M1,M2,M3<span style="color: #339933;">&gt;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> _m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> _m2<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>M3<span style="color: #339933;">&gt;</span> _m3<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> Set3<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> m1,IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> m2,IModel<span style="color: #339933;">&lt;</span>M3<span style="color: #339933;">&gt;</span> m3<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;_m1=m1<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_m2=m2<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_m3=m3<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;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> IModel<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> apply<span style="color: #009900;">&#40;</span>Function3<span style="color: #339933;">&lt;</span>T, M1, M2, M3<span style="color: #339933;">&gt;</span> function<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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Transformator.<span style="color: #006633;">Model3</span><span style="color: #339933;">&lt;</span>T, M1, M2, M3<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>_m1,_m2,_m3, function<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><span style="color: #009900;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Wir man erkennen kann, bestehen diese Klassen auch wieder aus drei Kopien, die mehr oder weniger die selbe Funktion, nur andere Parameter haben. Bis jetzt muss das Bild noch verschwommen sein, mit dem letzten Baustein sollte es sich klären.</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.wicket.model</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.model.IModel</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">de.wicketpraxis.wicket.model.transformation.ModelSet</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;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> Models</li><li><span style="color: #009900;">&#123;</span></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>T,M1<span style="color: #339933;">&gt;</span> ModelSet.<span style="color: #006633;">Set1</span><span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> on<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> model<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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ModelSet.<span style="color: #006633;">Set1</span><span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>model<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></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>T,M1,M2<span style="color: #339933;">&gt;</span> ModelSet.<span style="color: #006633;">Set2</span><span style="color: #339933;">&lt;</span>M1,M2<span style="color: #339933;">&gt;</span> on<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> model,IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> model2<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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ModelSet.<span style="color: #006633;">Set2</span><span style="color: #339933;">&lt;</span>M1,M2<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>model,model2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></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>T,M1,M2,M3<span style="color: #339933;">&gt;</span> ModelSet.<span style="color: #006633;">Set3</span><span style="color: #339933;">&lt;</span>M1,M2,M3<span style="color: #339933;">&gt;</span> on<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>M1<span style="color: #339933;">&gt;</span> model,IModel<span style="color: #339933;">&lt;</span>M2<span style="color: #339933;">&gt;</span> model2,IModel<span style="color: #339933;">&lt;</span>M3<span style="color: #339933;">&gt;</span> model3<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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ModelSet.<span style="color: #006633;">Set3</span><span style="color: #339933;">&lt;</span>M1,M2,M3<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>model,model2,model3<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>Fertig. Nun, vielleicht noch nicht ganz. Wir haben eine ganze Reihe von Klassen, eine ganze Menge Code, um die selben Anforderungen zu Erfüllen, wie mit dem im ersten Moment sehr viel einfacher gehaltenen Model-Ansatz aus dem anderen Artikel? Sehen wir uns daher das ganze in der Anwendung an.</p>
<p><strong>Beispiel</strong></p>
<p>In dem folgenden Beispiel benötigen wir ein Model, das eine Zufallszahl bereitstellt:</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.migration.model.transformation</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.model.LoadableDetachableModel</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> RandomNumberModel <span style="color: #000000; font-weight: bold;">extends</span> LoadableDetachableModel<span style="color: #339933;">&lt;</span>Double<span style="color: #339933;">&gt;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;@<span style="color: #003399; font-weight: bold;">Override</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399; font-weight: bold;">Double</span> load<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;">return</span> <span style="color: #003399; font-weight: bold;">Math</span>.<span style="color: #006633;">random</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>Diese Modell benutzen wir auf einer Seite als Datenquelle:</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.migration.model.transformation</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.ajax.AjaxSelfUpdatingTimerBehavior</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.WebMarkupContainer</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.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.util.time.Duration</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">de.wicketpraxis.wicket.model.Models</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">de.wicketpraxis.wicket.model.transformation.Function1</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">de.wicketpraxis.wicket.model.transformation.Function2</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> TransformationPage <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> TransformationPage<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;IModel<span style="color: #339933;">&lt;</span>Double<span style="color: #339933;">&gt;</span> randModel1=<span style="color: #000000; font-weight: bold;">new</span> RandomNumberModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>Double<span style="color: #339933;">&gt;</span> randModel2=<span style="color: #000000; font-weight: bold;">new</span> RandomNumberModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>Double<span style="color: #339933;">&gt;</span> diffResult = Models.<span style="color: #006633;">on</span><span style="color: #009900;">&#40;</span>randModel1, randModel2<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Function2<span style="color: #339933;">&lt;</span>Double, <span style="color: #003399; font-weight: bold;">Double</span>, Double<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;">Double</span> apply<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Double</span> value, <span style="color: #003399; font-weight: bold;">Double</span> value2<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;">return</span> value-value2<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;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> scaleResult = Models.<span style="color: #006633;">on</span><span style="color: #009900;">&#40;</span>randModel1<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Function1<span style="color: #339933;">&lt;</span>Integer, Double<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;">Integer</span> apply<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Double</span> value<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;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">*</span>100<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;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;WebMarkupContainer ajaxUpdate=<span style="color: #000000; font-weight: bold;">new</span> WebMarkupContainer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajaxUpdate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;ajaxUpdate.<span style="color: #006633;">setOutputMarkupId</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;ajaxUpdate.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AjaxSelfUpdatingTimerBehavior<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Duration</span>.<span style="color: #006633;">seconds</span><span style="color: #009900;">&#40;</span>1<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;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;ajaxUpdate.<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;rand1&quot;</span>,randModel1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;ajaxUpdate.<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;rand2&quot;</span>,randModel2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;ajaxUpdate.<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;diffResult&quot;</span>,diffResult<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;ajaxUpdate.<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;scaleResult&quot;</span>,scaleResult<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>ajaxUpdate<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>In diesem Beispiel erstellen wir zwei unabhängige Modelle für jeweils zwei Zufallszahlen. Diese werden über zwei Funktionsinstanzen manipuliert und als Model bereitgestellt. Dabei ist zu beachten, dass nicht das Ergebnis als Model bereitgestellt wird, sondern dass ein Model erzeugt wird, bei dem beim ersten Aufruf von getObject() die load()-Methode des LoadableDetachedModel aufgerufen wird, dass dann dort die Daten aus den referenzierten Modellen ermittelt und durch die Funktion transformiert. Das Ergebnis wird bis zum Aufruf von detach() (durch die angebundene Komponente) gepuffert.</p>
<p>Damit die Zufallszahlen immer wieder erzeugt werden, lassen wir die Anzeige sich per Ajax selbsttätig aktualisieren.</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>Transformation Page<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;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Zufallszahlen<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> wicket:<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ajaxUpdate&quot;</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Nummer 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</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;rand1&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;">td</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Nummer 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</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;rand2&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;">td</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Number 1*100<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</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;scaleResult&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;">td</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Number 1-Nummer 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</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;diffResult&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;">td</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</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><strong>Fazit</strong></p>
<p>Wo liegt jetzt der Vorteil? Zum einen sind die Implementierungen einfacher, da laut Schnittstellendefinition nur eine Methode implementiert werden muss. Zum anderen muss man nicht die benutzten Model-Klassen kennen, die diese Transformationen durchführen. Die Lesbarkeit ist wesentlich besser, weil aus dem Code abgeleitet werden kann, was da in etwa passiert.</p>
<p>Ist das der Weisheit letzter Schluss? Vermutlich nicht. Anregungen sind daher willkommen.</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%2F10%2F28%2Fwicket-model-transformation%2F&amp;title=Wicket%20Model%20Transformation&amp;bodytext=Eine%20Liste%20von%20Ergebnissen%20aus%20einer%20Tabelle%20in%20der%20Datenbank%20zu%20laden%20und%20%C3%BCber%20ein%20Model%20zur%20Verf%C3%BCgung%20zu%20stellen%2C%20ist%20eine%20recht%20einfache%20Angelegenheit.%20Wicket%20sorgt%20daf%C3%BCr%2C%20dass%20die%20Liste%20kein%20zweites%20mal%20geladen%20wird%2C%20nur%20weil%20das%20Model%20durch%20e" 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%2F10%2F28%2Fwicket-model-transformation%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%2F10%2F28%2Fwicket-model-transformation%2F&amp;title=Wicket%20Model%20Transformation&amp;notes=Eine%20Liste%20von%20Ergebnissen%20aus%20einer%20Tabelle%20in%20der%20Datenbank%20zu%20laden%20und%20%C3%BCber%20ein%20Model%20zur%20Verf%C3%BCgung%20zu%20stellen%2C%20ist%20eine%20recht%20einfache%20Angelegenheit.%20Wicket%20sorgt%20daf%C3%BCr%2C%20dass%20die%20Liste%20kein%20zweites%20mal%20geladen%20wird%2C%20nur%20weil%20das%20Model%20durch%20e" 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%2F10%2F28%2Fwicket-model-transformation%2F&amp;t=Wicket%20Model%20Transformation" 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%2F10%2F28%2Fwicket-model-transformation%2F&amp;title=Wicket%20Model%20Transformation" 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%2F10%2F28%2Fwicket-model-transformation%2F&amp;title=Wicket%20Model%20Transformation&amp;annotation=Eine%20Liste%20von%20Ergebnissen%20aus%20einer%20Tabelle%20in%20der%20Datenbank%20zu%20laden%20und%20%C3%BCber%20ein%20Model%20zur%20Verf%C3%BCgung%20zu%20stellen%2C%20ist%20eine%20recht%20einfache%20Angelegenheit.%20Wicket%20sorgt%20daf%C3%BCr%2C%20dass%20die%20Liste%20kein%20zweites%20mal%20geladen%20wird%2C%20nur%20weil%20das%20Model%20durch%20e" 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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>22. September 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/09/22/migration-zu-wicket-model/" title="Migration zu Wicket: Model">Migration zu Wicket: Model</a></li><li>3. Januar 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/01/03/modell-referenzen/" title="Modell-Referenzen">Modell-Referenzen</a></li><li>4. November 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/11/04/dont-use-property-model-at-all/" title="PropertyModel &#8211; einfach ist nicht immer gut">PropertyModel &#8211; einfach ist nicht immer gut</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2009/10/28/wicket-model-transformation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wicket Tipps: Markup</title>
		<link>http://www.wicket-praxis.de/blog/2009/10/27/wicket-tipps-markup/</link>
		<comments>http://www.wicket-praxis.de/blog/2009/10/27/wicket-tipps-markup/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 07:05:16 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[reload]]></category>
		<category><![CDATA[resource]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=172</guid>
		<description><![CDATA[Ich benutze für alle Projekte Maven. Der eine oder andere mag mit Maven auf dem Kriegsfuß stehen (was ich zwar nicht verstehe, aber akzeptiere). Bisher war ich (und an anderer Stelle war es auch nicht notwendig, darüber nachzudenken) für eine saubere Trennung von Code und Resourcen. Das bedeutet z.B. das der Code einer Wicket-Komponente z.B. [...]]]></description>
			<content:encoded><![CDATA[<p>Ich benutze für alle Projekte Maven. Der eine oder andere mag mit Maven auf dem Kriegsfuß stehen (was ich zwar nicht verstehe, aber akzeptiere). Bisher war ich (und an anderer Stelle war es auch nicht notwendig, darüber nachzudenken) für eine saubere Trennung von Code und Resourcen. Das bedeutet z.B. das der Code einer Wicket-Komponente z.B. im Pfad src/main/java/de/wicketpraxis/ zu finden ist und das Markup in src/main/resources/de/wicketpraxis.</p>
<p>Das Projekt wächst und gedeiht und es entstehen unzählige Komponenten (ein Zeichen dafür, dass man mit Wicket sehr sehr einfach eigene Komponenten erstellen kann).&nbsp; Im Laufe der Zeit hat es sich als unpraktisch herausgestellt, in der IDE immer zwischen diesen beiden Verzeichnissen zu wechseln. Auch beim Refactoring kann es sich als lästig erweisen, weil man an zwei Stellen die selbe Operation anwenden muss (zumindest in Eclipse).</p>
<p>Ich habe daher alle Projekte umgestellt und kann nun die Markup-Dateien in das selbe Verzeichnis/Package wie die Komponente legen. Die Angst, dass die Übersichtlichkeit leidet, hat sich als unbegründet erwiesen, die Produktivität ist spürbar besser. Folgende Anpassung muss man daher in einem Projekt vornehmen. In der pom.xml ist folgender Block einzufügen:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="XML"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>...</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>src/main/resources<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>src/main/java<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;excludes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>**/*.java<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exclude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/excludes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li>...</li><li>&nbsp;&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Wenn man nun die Anwendung über Jetty aus dem Projekt heraus starten möchte, empfiehlt sich ein Ansatz, den ich bereits im folgenden Beitrag erwähnt habe: <a href="http://www.wicket-praxis.de/blog/2008/12/31/wicket-resourcen-mit-jetty-nachladen/" target="_blank">Wicket Resourcen mit Jetty nachladen</a>. Allerdings müssen wir dazu den angepassten ResourceStreamLocator entsprechend erweitern. Am besten wir schreiben eine neue Klasse:</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.wicket.util.resource</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.util.file.File</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.resource.FileResourceStream</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.resource.IResourceStream</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.resource.locator.ResourceStreamLocator</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.slf4j.Logger</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.slf4j.LoggerFactory</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> MavenDevResourceAndSourceStreamLocator <span style="color: #000000; font-weight: bold;">extends</span> ResourceStreamLocator</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 = LoggerFactory.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>MavenDevResourceAndSourceStreamLocator.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399; font-weight: bold;">String</span> MAVEN_RESOURCE_PATH=<span style="color: #0000ff;">&quot;src/main/resources/&quot;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399; font-weight: bold;">String</span> MAVEN_JAVASOURCE_PATH=<span style="color: #0000ff;">&quot;src/main/java/&quot;</span><span style="color: #339933;">;</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> IResourceStream locate<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Class<span style="color: #339933;">&lt;?&gt;</span> clazz, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399; font-weight: bold;">String</span> path<span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;IResourceStream located=getFileSysResourceStream<span style="color: #009900;">&#40;</span>MAVEN_RESOURCE_PATH,path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>located==<span style="color: #006600; font-weight: bold;">null</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;located=getFileSysResourceStream<span style="color: #009900;">&#40;</span>MAVEN_JAVASOURCE_PATH,path<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;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>located <span style="color: #339933;">!</span>= <span style="color: #006600; font-weight: bold;">null</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;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_logger.<span style="color: #006633;">isInfoEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> _logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Locate: &quot;</span> + clazz + <span style="color: #0000ff;">&quot; in &quot;</span> + path+<span style="color: #0000ff;">&quot; -&gt; &quot;</span>+located<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">return</span> located<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;located=<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">locate</span><span style="color: #009900;">&#40;</span>clazz, path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_logger.<span style="color: #006633;">isInfoEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> _logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Locate: &quot;</span> + clazz + <span style="color: #0000ff;">&quot; in &quot;</span> + path+<span style="color: #0000ff;">&quot; -&gt; &quot;</span>+located+<span style="color: #0000ff;">&quot;(Fallback)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp;&nbsp;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">return</span> located<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: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> IResourceStream getFileSysResourceStream<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> prefix, <span style="color: #003399; font-weight: bold;">String</span> path<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: #003399; font-weight: bold;">File</span> f=<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">File</span><span style="color: #009900;">&#40;</span>prefix+path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">isFile</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></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;">return</span> <span style="color: #000000; font-weight: bold;">new</span> FileResourceStream<span style="color: #009900;">&#40;</span>f<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;">return</span> <span style="color: #006600; font-weight: bold;">null</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 Einbindung funktioniert wie beim letzten Mal:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Java(TM) 2 Platform Standard Edition 5.0"><div class="devcodeoverflow"><ol><li><span style="color: #000000;&nbsp;&nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>DEVELOPMENT.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span>configurationType<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;getResourceSettings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setResourceStreamLocator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MavenDevResourceAndSourceStreamLocator<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><span style="color: #009900;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Jetzt sollte man (wenn alles andere entsprechend vorbereitet ist) mit <strong>mvn jetty:run -Dwicket.configuration=development</strong> Jetty aus dem Projekt heraus starten können. Sobald man Änderungen am Markup vorgenommen hat, werden diese neu geladen.</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%2F10%2F27%2Fwicket-tipps-markup%2F&amp;title=Wicket%20Tipps%3A%20Markup&amp;bodytext=Ich%20benutze%20f%C3%BCr%20alle%20Projekte%20Maven.%20Der%20eine%20oder%20andere%20mag%20mit%20Maven%20auf%20dem%20Kriegsfu%C3%9F%20stehen%20%28was%20ich%20zwar%20nicht%20verstehe%2C%20aber%20akzeptiere%29.%20Bisher%20war%20ich%20%28und%20an%20anderer%20Stelle%20war%20es%20auch%20nicht%20notwendig%2C%20dar%C3%BCber%20nachzudenken%29%20f%C3%BCr%20eine%20sau" 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%2F10%2F27%2Fwicket-tipps-markup%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%2F10%2F27%2Fwicket-tipps-markup%2F&amp;title=Wicket%20Tipps%3A%20Markup&amp;notes=Ich%20benutze%20f%C3%BCr%20alle%20Projekte%20Maven.%20Der%20eine%20oder%20andere%20mag%20mit%20Maven%20auf%20dem%20Kriegsfu%C3%9F%20stehen%20%28was%20ich%20zwar%20nicht%20verstehe%2C%20aber%20akzeptiere%29.%20Bisher%20war%20ich%20%28und%20an%20anderer%20Stelle%20war%20es%20auch%20nicht%20notwendig%2C%20dar%C3%BCber%20nachzudenken%29%20f%C3%BCr%20eine%20sau" 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%2F10%2F27%2Fwicket-tipps-markup%2F&amp;t=Wicket%20Tipps%3A%20Markup" 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%2F10%2F27%2Fwicket-tipps-markup%2F&amp;title=Wicket%20Tipps%3A%20Markup" 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%2F10%2F27%2Fwicket-tipps-markup%2F&amp;title=Wicket%20Tipps%3A%20Markup&amp;annotation=Ich%20benutze%20f%C3%BCr%20alle%20Projekte%20Maven.%20Der%20eine%20oder%20andere%20mag%20mit%20Maven%20auf%20dem%20Kriegsfu%C3%9F%20stehen%20%28was%20ich%20zwar%20nicht%20verstehe%2C%20aber%20akzeptiere%29.%20Bisher%20war%20ich%20%28und%20an%20anderer%20Stelle%20war%20es%20auch%20nicht%20notwendig%2C%20dar%C3%BCber%20nachzudenken%29%20f%C3%BCr%20eine%20sau" 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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>31. Dezember 2008 -- <a href="http://www.wicket-praxis.de/blog/2008/12/31/wicket-resourcen-mit-jetty-nachladen/" title="Wicket Resourcen mit Jetty nachladen">Wicket Resourcen mit Jetty nachladen</a></li><li>13. Januar 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/01/13/wicket-und-eclipse/" title="Wicket und Eclipse">Wicket und Eclipse</a></li><li>15. Juli 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/07/15/wicket-flexibilitat-mit-factories/" title="Wicket &#8211; Flexibilität mit Factories">Wicket &#8211; Flexibilität mit Factories</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2009/10/27/wicket-tipps-markup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wicket &#8220;stateless&#8221; &#8211; keine einfache Herausforderung</title>
		<link>http://www.wicket-praxis.de/blog/2009/07/30/wicket-stateless-keine-einfache-herausforderung/</link>
		<comments>http://www.wicket-praxis.de/blog/2009/07/30/wicket-stateless-keine-einfache-herausforderung/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 10:18:57 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[stateless]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=88</guid>
		<description><![CDATA[Wie in den Kommentaren der letzten Tage sichtbar wurde, eignet sich Wicket nicht &#8220;ungeschminkt&#8221; für Webseiten, die ihre Zustandsinformationen klassisch in URL-Parametern ablegen. In meinem Buch beschreibe ich eine einfache Variante, die bereits zum Ziel führen kann.
Die Herausforderung liegt darin, dass man von den Vorteilen, die Wicket mitbringt nicht all zu viele einbüßt. Daher werde [...]]]></description>
			<content:encoded><![CDATA[<p>Wie in den Kommentaren der letzten Tage sichtbar wurde, eignet sich Wicket nicht &#8220;ungeschminkt&#8221; für Webseiten, die ihre Zustandsinformationen klassisch in URL-Parametern ablegen. In meinem Buch beschreibe ich eine einfache Variante, die bereits zum Ziel führen kann.</p>
<p>Die Herausforderung liegt darin, dass man von den Vorteilen, die Wicket mitbringt nicht all zu viele einbüßt. Daher werde ich mich in den nächsten Tagen mal damit beschäftigen, wie man mit möglichst wenig Aufwand Anwendungen realisieren kann, die auf der einen Seite URL-Parameter benutzen, auf der anderen Seite aber nicht auf saubere Komponenten verzichten müssen.</p>
<p>Auch wenn es schwer ist, sich von der Herangehensweise wie man sie mit JSP,PHP,&#8230; gewöhnt ist, zu lösen, erschließt man das volle Potential von Wicket erst dann, wenn man sich auf den &#8220;Wicket-Pfad&#8221; begibt. Der einzige Aspekt, der es notwendig macht, sich mit der Frage von URL-Parametern zu beschäftigen, ist die Suchmaschinentauglichkeit der Anwendung. Da muss man allerdings auch überlegen, ob man nicht einen Sitemap generiert, die alle gewünschten Inhalte ansteuerbar macht, so dass man nicht gezwungen ist, eine SEO-taugliche Navigation aufzusetzen.</p>
<p>Wicket ist ganz sicher nicht für jede Anforderung geeignet. Unbestritten. Die Alternativen sind IMHO allerdings auch nicht zufriedenstellender.</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%2F07%2F30%2Fwicket-stateless-keine-einfache-herausforderung%2F&amp;title=Wicket%20%22stateless%22%20-%20keine%20einfache%20Herausforderung&amp;bodytext=Wie%20in%20den%20Kommentaren%20der%20letzten%20Tage%20sichtbar%20wurde%2C%20eignet%20sich%20Wicket%20nicht%20%22ungeschminkt%22%20f%C3%BCr%20Webseiten%2C%20die%20ihre%20Zustandsinformationen%20klassisch%20in%20URL-Parametern%20ablegen.%20In%20meinem%20Buch%20beschreibe%20ich%20eine%20einfache%20Variante%2C%20die%20bereits%20zum%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%2F07%2F30%2Fwicket-stateless-keine-einfache-herausforderung%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%2F07%2F30%2Fwicket-stateless-keine-einfache-herausforderung%2F&amp;title=Wicket%20%22stateless%22%20-%20keine%20einfache%20Herausforderung&amp;notes=Wie%20in%20den%20Kommentaren%20der%20letzten%20Tage%20sichtbar%20wurde%2C%20eignet%20sich%20Wicket%20nicht%20%22ungeschminkt%22%20f%C3%BCr%20Webseiten%2C%20die%20ihre%20Zustandsinformationen%20klassisch%20in%20URL-Parametern%20ablegen.%20In%20meinem%20Buch%20beschreibe%20ich%20eine%20einfache%20Variante%2C%20die%20bereits%20zum%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%2F07%2F30%2Fwicket-stateless-keine-einfache-herausforderung%2F&amp;t=Wicket%20%22stateless%22%20-%20keine%20einfache%20Herausforderung" 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%2F07%2F30%2Fwicket-stateless-keine-einfache-herausforderung%2F&amp;title=Wicket%20%22stateless%22%20-%20keine%20einfache%20Herausforderung" 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%2F07%2F30%2Fwicket-stateless-keine-einfache-herausforderung%2F&amp;title=Wicket%20%22stateless%22%20-%20keine%20einfache%20Herausforderung&amp;annotation=Wie%20in%20den%20Kommentaren%20der%20letzten%20Tage%20sichtbar%20wurde%2C%20eignet%20sich%20Wicket%20nicht%20%22ungeschminkt%22%20f%C3%BCr%20Webseiten%2C%20die%20ihre%20Zustandsinformationen%20klassisch%20in%20URL-Parametern%20ablegen.%20In%20meinem%20Buch%20beschreibe%20ich%20eine%20einfache%20Variante%2C%20die%20bereits%20zum%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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>4. August 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/08/04/web-1-0-mit-wicket-seitenparameter-und-links/" title="Web 1.0 mit Wicket &#8211; Seitenparameter und Links">Web 1.0 mit Wicket &#8211; Seitenparameter und Links</a></li><li>21. Juli 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/07/21/wicket-saved-the-day/" title="Wicket saved the day">Wicket saved the day</a></li><li>15. Juli 2010 -- <a href="http://www.wicket-praxis.de/blog/2010/07/15/wicket-flexibilitat-mit-factories/" title="Wicket &#8211; Flexibilität mit Factories">Wicket &#8211; Flexibilität mit Factories</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2009/07/30/wicket-stateless-keine-einfache-herausforderung/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Wicket und Scala &#8211; der Rückweg ist anstrengend</title>
		<link>http://www.wicket-praxis.de/blog/2009/06/19/wicket-scala/</link>
		<comments>http://www.wicket-praxis.de/blog/2009/06/19/wicket-scala/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 07:20:14 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Wicket]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[lines]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=70</guid>
		<description><![CDATA[Ich habe mal ein wenig mit Scala rumgespielt und mit den Sprachmöglichkeiten, die Scala bietet, versucht aus einem Java-lastigen Wicket-Beispiel etwas zu machen, was sich wie Scala anfühlt. Zuerst der Java-Code:
package de.flapdoodle.incubator.scalawicket.web.pages;&#160;import org.apache.wicket.Component;import org.apache.wicket.IClusterable;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.markup.html.WebPage;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.form.Form;import org.apache.wicket.markup.html.form.TextField;import org.apache.wicket.model.CompoundPropertyModel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.Model;import org.apache.wicket.model.PropertyModel;&#160;public class StartJava extends WebPage&#123;&#160;&#160;public StartJava&#40;&#41;&#160;&#160;&#123;&#160;&#160;&#160;&#160;IModel messageModel=Model.of&#40;&#34;Huiii&#34;&#41;;&#160;&#160;&#160;&#160;final Label label=new Label&#40;&#34;message&#34;,messageModel&#41;;&#160;&#160;&#160;&#160;label.setOutputMarkupId&#40;true&#41;;&#160;&#160;&#160;&#160;&#160;add&#40;label&#41;;&#160;&#160;&#160;&#160;&#160;final Bean [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe mal ein wenig mit Scala rumgespielt und mit den Sprachmöglichkeiten, die Scala bietet, versucht aus einem Java-lastigen Wicket-Beispiel etwas zu machen, was sich wie Scala anfühlt. Zuerst der Java-Code:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Java"><div class="devcodeoverflow"><ol><li><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.flapdoodle.incubator.scalawicket.web.pages</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.Component</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.IClusterable</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.AjaxRequestTarget</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.markup.html.AjaxFallbackLink</span><span style="color: #339933;">;</span></li><li><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.wicket.ajax.markup.html.AjaxLink</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.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.form.Form</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.form.TextField</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.CompoundPropertyModel</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.model.PropertyModel</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> StartJava <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> StartJava<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;IModel messageModel<span style="color: #339933;">=</span>Model.<span style="color: #006633;">of</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Huiii&quot;</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;">final</span> <span style="color: #003399;">Label</span> label<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span>,messageModel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;label.<span style="color: #006633;">setOutputMarkupId</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></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>label<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">final</span> Bean bean<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Bean<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;bean.<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Klaus&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;bean.<span style="color: #006633;">setAlter</span><span style="color: #009900;">&#40;</span>12<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Component</span> labelName <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span>,<span style="color: #000000; font-weight: bold;">new</span> PropertyModel<span style="color: #009900;">&#40;</span>bean,<span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setOutputMarkupId</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></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Component</span> labelAlter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;alter&quot;</span>,<span style="color: #000000; font-weight: bold;">new</span> PropertyModel<span style="color: #009900;">&#40;</span>bean,<span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setOutputMarkupId</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></li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>labelName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>labelAlter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">final</span> 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;form&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> CompoundPropertyModel<span style="color: #009900;">&#40;</span>bean<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;form.<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;">TextField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<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;">TextField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;alter&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;form.<span style="color: #006633;">setOutputMarkupId</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></li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span>form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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> AjaxFallbackLink<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span>,messageModel<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: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span>AjaxRequestTarget target<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;getModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setObject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Klick&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bean.<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Peter&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>label<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>labelName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>labelAlter<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;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AjaxLink<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link2&quot;</span>,messageModel<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;@Override</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span>AjaxRequestTarget target<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;getModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setObject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Klack&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bean.<span style="color: #006633;">setAlter</span><span style="color: #009900;">&#40;</span>24<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>label<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>labelName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #006633;">addComponent</span><span style="color: #009900;">&#40;</span>labelAlter<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>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">class</span> Bean <span style="color: #000000; font-weight: bold;">implements</span> IClusterable</li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #003399;">String</span> _name<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000066; font-weight: bold;">int</span> _alter<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getName<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;">return</span> _name<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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<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;_name <span style="color: #339933;">=</span> name<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;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getAlter<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;">return</span> _alter<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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAlter<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> alter<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;_alter <span style="color: #339933;">=</span> alter<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><span style="color: #009900;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--><br />
.. und nun das ganze in Scala<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Scala"><div class="devcodeoverflow"><ol><li><span style="color: #0000ff; font-weight: bold;">package</span> de.<span style="color: #000000;">flapdoodle</span>.<span style="color: #000000;">incubator</span>.<span style="color: #000000;">scalawicket</span>.<span style="color: #000000;">web</span>.<span style="color: #000000;">pages</span><span style="color: #000080;">;</span></li><li>&nbsp;</li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">Component</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">IClusterable</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">ajax</span>.<span style="color: #000000;">AjaxRequestTarget</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">ajax</span>.<span style="color: #000000;">markup</span>.<span style="color: #000000;">html</span>.<span style="color: #000000;">AjaxFallbackLink</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">ajax</span>.<span style="color: #000000;">markup</span>.<span style="color: #000000;">html</span>.<span style="color: #000000;">AjaxLink</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">markup</span>.<span style="color: #000000;">html</span>.<span style="color: #000000;">WebPage</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">markup</span>.<span style="color: #000000;">html</span>.<span style="color: #000000;">basic</span>.<span style="color: #000000;">Label</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">markup</span>.<span style="color: #000000;">html</span>.<span style="color: #000000;">form</span>.<span style="color: #000000;">Form</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">markup</span>.<span style="color: #000000;">html</span>.<span style="color: #000000;">form</span>.<span style="color: #000000;">TextField</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">model</span>.<span style="color: #000000;">CompoundPropertyModel</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">model</span>.<span style="color: #000000;">IModel</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">model</span>.<span style="color: #000000;">Model</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">apache</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">model</span>.<span style="color: #000000;">PropertyModel</span><span style="color: #000080;">;</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> de.<span style="color: #000000;">flapdoodle</span>.<span style="color: #000000;">incubator</span>.<span style="color: #000000;">scalawicket</span>.<span style="color: #000000;">web</span>.<span style="color: #000000;">wicket</span>.<span style="color: #000000;">WicketHelper</span>.<span style="color: #000080;">_</span></li><li><span style="color: #0000ff; font-weight: bold;">import</span> scala.<span style="color: #000000;">reflect</span>.<span style="color: #000000;">BeanProperty</span><span style="color: #000080;">;</span></li><li>&nbsp;</li><li><span style="color: #0000ff; font-weight: bold;">class</span> Start <span style="color: #0000ff; font-weight: bold;">extends</span> WebPage </li><li><span style="color: #F78811;">&#123;</span></li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">val</span> messageModel<span style="color: #000080;">=</span>Model.<span style="color: #000000;">of</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;Huiii&quot;</span><span style="color: #F78811;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">val</span> label<span style="color: #000080;">=</span><span style="color: #0000ff; font-weight: bold;">new</span> Label<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;message&quot;</span>,messageModel<span style="color: #F78811;">&#41;</span></li><li>&nbsp;&nbsp;label.<span style="color: #000000;">enableAjax</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">this</span>+<span style="color: #000080;">=</span>label<span style="color: #000080;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">val</span> bean<span style="color: #000080;">=</span><span style="color: #0000ff; font-weight: bold;">new</span> Bean</li><li>&nbsp;&nbsp;bean.<span style="color: #000000;">name</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;Klaus&quot;</span><span style="color: #000080;">;</span></li><li>&nbsp;&nbsp;bean.<span style="color: #000000;">alter</span><span style="color: #000080;">=</span><span style="color: #F78811;">12</span><span style="color: #000080;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">val</span> labelName <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Label<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;name&quot;</span>,bean model <span style="color: #F78811;">&#123;</span><span style="color: #000080;">_</span>.<span style="color: #000000;">name</span><span style="color: #F78811;">&#125;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">enableAjax</span></li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">val</span> labelAlter <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Label<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;alter&quot;</span>,bean model <span style="color: #F78811;">&#123;</span><span style="color: #000080;">_</span>.<span style="color: #000000;">alter</span><span style="color: #F78811;">&#125;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">enableAjax</span></li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">this</span>+<span style="color: #000080;">=</span>labelName</li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">this</span>+<span style="color: #000080;">=</span>labelAlter</li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">val</span> form<span style="color: #000080;">=</span><span style="color: #0000ff; font-weight: bold;">new</span> Form<span style="color: #F78811;">&#91;</span>Bean<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;form&quot;</span>, <span style="color: #0000ff; font-weight: bold;">new</span> CompoundPropertyModel<span style="color: #F78811;">&#91;</span>Bean<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>bean<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #000080;">;</span></li><li>&nbsp;&nbsp;form+<span style="color: #000080;">=</span><span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">new</span> TextField<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;name&quot;</span><span style="color: #F78811;">&#41;</span>,<span style="color: #0000ff; font-weight: bold;">new</span> TextField<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;alter&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span></li><li>&nbsp;&nbsp;form.<span style="color: #000000;">enableAjax</span></li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">this</span>+<span style="color: #000080;">=</span>form</li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">this</span>+<span style="color: #000080;">=</span><span style="color: #0000ff; font-weight: bold;">new</span> AjaxFallbackLink<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;link&quot;</span>,messageModel<span style="color: #F78811;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #F78811;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">override</span> <span style="color: #0000ff; font-weight: bold;">def</span> onClick<span style="color: #F78811;">&#40;</span>target<span style="color: #000080;">:</span> AjaxRequestTarget<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> </li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #F78811;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">this</span>.<span style="color: #000000;">model</span> set <span style="color: #6666FF;">&quot;Klick&quot;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bean.<span style="color: #000000;">name</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;Peter&quot;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #000000;">refresh</span><span style="color: #F78811;">&#40;</span>form,label,labelName,labelAlter<span style="color: #F78811;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #F78811;">&#125;</span></li><li>&nbsp;&nbsp;<span style="color: #F78811;">&#125;</span><span style="color: #000080;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">this</span>+<span style="color: #000080;">=</span><span style="color: #0000ff; font-weight: bold;">new</span> AjaxLink<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;link2&quot;</span>,messageModel<span style="color: #F78811;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #F78811;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">override</span> <span style="color: #0000ff; font-weight: bold;">def</span> onClick<span style="color: #F78811;">&#40;</span>target<span style="color: #000080;">:</span> AjaxRequestTarget<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #F78811;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">this</span>.<span style="color: #000000;">model</span> set <span style="color: #6666FF;">&quot;Klack&quot;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bean.<span style="color: #000000;">alter</span><span style="color: #000080;">=</span>24</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target.<span style="color: #000000;">refresh</span><span style="color: #F78811;">&#40;</span>form,label,labelName,labelAlter<span style="color: #F78811;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #F78811;">&#125;</span></li><li>&nbsp;&nbsp;<span style="color: #F78811;">&#125;</span><span style="color: #000080;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">class</span> Bean <span style="color: #0000ff; font-weight: bold;">extends</span> IClusterable</li><li>&nbsp;&nbsp;<span style="color: #F78811;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000080;">@</span>BeanProperty</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">var</span> name<span style="color: #000080;">:</span> String <span style="color: #000080;">=</span> <span style="color: #000080;">_;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000080;">@</span>BeanProperty</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff; font-weight: bold;">var</span> alter<span style="color: #000080;">:</span> Integer <span style="color: #000080;">=</span> <span style="color: #000080;">_;</span></li><li>&nbsp;&nbsp;<span style="color: #F78811;">&#125;</span></li><li><span style="color: #F78811;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--><br />
Zuerst zu den offensichtlichen Dingen:</p>
<ul>
<li>Java: Zeilen=91, Wörter=155, Zeichen=2.567</li>
<li>Scala: Zeilen=69(75%), Wörter=126(81%), Zeichen=1.921(75%)</li>
</ul>
<p>In diesem Beispiel kann Scala seine Vorteile vielleicht noch nicht richtig ausspielen. Wobei 25% weniger Schreibarbeit (wenn man vernachlässigt, dass ich einmalig etwas Scala-Code schreiben musste, was mir das ermöglicht) für dieses Beispiel vielleicht auch schon eine bemerkenswerte Menge ist.</p>
<p>Spannender ist folgender Umstand: Ich habe den Java-Code aus dem Scala-Code abgeleitet. Wenn ich das Beispiel direkt in Java geschrieben hätte, sähe der Code fast genauso aus. Als ich aber den Scala-Code rückübersetzte, fiel es mir sehr schwer, die ganzen Typ-Definitionen zu schreiben, die abschließende Semikolons zu setzen und Parameter in geschweifte Klammern einzubetten. Auch wenn die Unterstützung für Scala in Eclipse noch einiges Potential hat, kann man a) damit bereits erstaunlich gut arbeiten (wenn man bedenkt, welche interessanten Sprachmöglichkeiten (und damit Schwierigkeiten für eine IDE) Scala bietet).</p>
<p>Meine schönste Zeile Code ist in diesem Beispiel das Erzeugen eines AbstractReadOnlyModel durch den Aufruf von <strong>&#8220;bean model { _.alter }&#8221;</strong>, der in diesem Fall das selbe leistet wie ein PropertyModel, nur dass das Attribut nicht erst per Reflection ermittelt wird.</p>
<p>Ich warte eigentlich darauf, dass jemand Wicket nach Scala portiert, denn das Lift-Framework gefällt mir nicht so gut (da wird wieder Code in die Templates verlagert). Jetzt geht es erst einmal weiter mit Java, auch wenn der Rückweg jetzt schon ein beschwerlicher war.</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%2F19%2Fwicket-scala%2F&amp;title=Wicket%20und%20Scala%20-%20der%20R%C3%BCckweg%20ist%20anstrengend&amp;bodytext=Ich%20habe%20mal%20ein%20wenig%20mit%20Scala%20rumgespielt%20und%20mit%20den%20Sprachm%C3%B6glichkeiten%2C%20die%20Scala%20bietet%2C%20versucht%20aus%20einem%20Java-lastigen%20Wicket-Beispiel%20etwas%20zu%20machen%2C%20was%20sich%20wie%20Scala%20anf%C3%BChlt.%20Zuerst%20der%20Java-Code%3A%0D%0Apackage%20de.flapdoodle.incubator.sca" 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%2F19%2Fwicket-scala%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%2F19%2Fwicket-scala%2F&amp;title=Wicket%20und%20Scala%20-%20der%20R%C3%BCckweg%20ist%20anstrengend&amp;notes=Ich%20habe%20mal%20ein%20wenig%20mit%20Scala%20rumgespielt%20und%20mit%20den%20Sprachm%C3%B6glichkeiten%2C%20die%20Scala%20bietet%2C%20versucht%20aus%20einem%20Java-lastigen%20Wicket-Beispiel%20etwas%20zu%20machen%2C%20was%20sich%20wie%20Scala%20anf%C3%BChlt.%20Zuerst%20der%20Java-Code%3A%0D%0Apackage%20de.flapdoodle.incubator.sca" 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%2F19%2Fwicket-scala%2F&amp;t=Wicket%20und%20Scala%20-%20der%20R%C3%BCckweg%20ist%20anstrengend" 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%2F19%2Fwicket-scala%2F&amp;title=Wicket%20und%20Scala%20-%20der%20R%C3%BCckweg%20ist%20anstrengend" 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%2F19%2Fwicket-scala%2F&amp;title=Wicket%20und%20Scala%20-%20der%20R%C3%BCckweg%20ist%20anstrengend&amp;annotation=Ich%20habe%20mal%20ein%20wenig%20mit%20Scala%20rumgespielt%20und%20mit%20den%20Sprachm%C3%B6glichkeiten%2C%20die%20Scala%20bietet%2C%20versucht%20aus%20einem%20Java-lastigen%20Wicket-Beispiel%20etwas%20zu%20machen%2C%20was%20sich%20wie%20Scala%20anf%C3%BChlt.%20Zuerst%20der%20Java-Code%3A%0D%0Apackage%20de.flapdoodle.incubator.sca" 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>
<h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>26. August 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/08/26/scala-vs-java/" title="Scala vs Java">Scala vs Java</a></li><li>21. Juli 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/07/21/sails-die-scala-version-von-rails-grail/" title="Sails &#8211; die Scala Version von Rails/Grails">Sails &#8211; die Scala Version von Rails/Grails</a></li><li>7. Juli 2009 -- <a href="http://www.wicket-praxis.de/blog/2009/07/07/scala-kommt/" title="Scala kommt">Scala kommt</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.wicket-praxis.de/blog/2009/06/19/wicket-scala/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
