<?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; cascading</title>
	<atom:link href="http://www.wicket-praxis.de/blog/tag/cascading/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wicket-praxis.de/blog</link>
	<description>erfahrungen mit wicket aus dem projektalltag</description>
	<lastBuildDate>Fri, 26 Aug 2011 11:14:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Modell-Referenzen</title>
		<link>http://www.wicket-praxis.de/blog/2009/01/03/modell-referenzen/</link>
		<comments>http://www.wicket-praxis.de/blog/2009/01/03/modell-referenzen/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 10:15:11 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Wicket]]></category>
		<category><![CDATA[cascading]]></category>
		<category><![CDATA[detach]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://www.wicket-praxis.de/blog/?p=10</guid>
		<description><![CDATA[Wie zeige ich eine Liste von Elementen und die Länge der Liste mit Wicket an, ohne dass ich die Liste zweimal erzeugen muss? Für die Liste würde man ein LoadableDetachableModel benutzen und in load() das Ergebnis zurückliefern. final LoadableDetachableModel&#60;List&#60;Something&#62;&#62; modelListe = new LoadableDetachableModel&#60;List&#60;Something&#62;&#62;&#40;&#41;&#123;&#160;&#160;@Override&#160;&#160;protected List&#60;Something&#62; load&#40;&#41;&#160;&#160;&#123;&#160;&#160;&#160;&#160;return Something.asList&#40;&#41;;&#160;&#160;&#125;&#125;; Für die Anzahl der Einträge würde ich jetzt auf [...]]]></description>
			<content:encoded><![CDATA[<p>Wie zeige ich eine Liste von Elementen und die Länge der Liste mit Wicket an, ohne dass ich die Liste zweimal erzeugen muss?</p>
<p>Für die Liste würde man ein LoadableDetachableModel benutzen und in load() das Ergebnis zurückliefern.<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Java"><div class="devcodeoverflow"><ol><li><span style="color: #000000; font-weight: bold;">final</span> LoadableDetachableModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>Something<span style="color: #339933;">&gt;&gt;</span> modelListe <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LoadableDetachableModel<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>Something<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;@Override</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> List<span style="color: #339933;">&lt;</span>Something<span style="color: #339933;">&gt;</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> Something.<span style="color: #006633;">asList</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><span style="color: #339933;">;</span></li></ol></div></pre><!--END_DEVFMTCODE--><br />
Für die Anzahl der Einträge würde ich jetzt auf dieses Modell zurückgreifen:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Java"><div class="devcodeoverflow"><ol><li>LoadableDetachableModel<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> modelAnzahl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LoadableDetachableModel<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;@Override</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Integer</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> modelListe.<span style="color: #006633;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</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;@Override</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> detach<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;modelListe.<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: #000000; font-weight: bold;">super</span>.<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;<span style="color: #009900;">&#125;</span></li><li><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></li></ol></div></pre><!--END_DEVFMTCODE--><br />
Wenn modelListe nicht mit einer Wicketkomponente verbunden wäre, würde detach für diese Modell nie aufgerufen und die Liste damit nicht neu erzeugt. Änderungen an der Liste würden sich nicht sofort in der Anzeige wiederspiegeln. Daher muss man in dem Modell, dass mit einer Wicketkomponente verbunden ist auch detach für alle referenzierten Modelle aufrufen. Es gibt eine einfachere Lösung:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Java"><div class="devcodeoverflow"><ol><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> CascadingLoadableDetachableModel<span style="color: #339933;">&lt;</span>M,P<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> LoadableDetachableModel<span style="color: #339933;">&lt;</span>M<span style="color: #339933;">&gt;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;IModel<span style="color: #339933;">&lt;</span>P<span style="color: #339933;">&gt;</span> _parent<span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> CascadingLoadableDetachableModel<span style="color: #009900;">&#40;</span>IModel<span style="color: #339933;">&lt;</span>P<span style="color: #339933;">&gt;</span> parent<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><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;_parent<span style="color: #339933;">=</span>parent<span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;@Override</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> detach<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;">super</span>.<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;_parent.<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;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;@Override</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> M 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> load<span style="color: #009900;">&#40;</span>_parent.<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;<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> M load<span style="color: #009900;">&#40;</span>P parentModelData<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--><br />
Man übergibt die Modell-Referenz im Konstruktor, bekommt die Modell-Daten automatisch als Methodenparameter und detach wird auch automatisch aufgerufen:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Java"><div class="devcodeoverflow"><ol><li>CascadingLoadableDetachableModel<span style="color: #339933;">&lt;</span><span style="color: #003399;">Integer</span>,List<span style="color: #339933;">&lt;</span>Something<span style="color: #339933;">&gt;&gt;</span> modelAnzahl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CascadingLoadableDetachableModel<span style="color: #339933;">&lt;</span><span style="color: #003399;">Integer</span>,List<span style="color: #339933;">&lt;</span>Something<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;@Override</li><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Integer</span> load<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Something<span style="color: #339933;">&gt;</span> parentModelData<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> parentModelData.<span style="color: #006633;">size</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><span style="color: #339933;">;</span></li></ol></div></pre><!--END_DEVFMTCODE--><br />
Schön kurz.</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%2F01%2F03%2Fmodell-referenzen%2F&amp;title=Modell-Referenzen&amp;bodytext=Wie%20zeige%20ich%20eine%20Liste%20von%20Elementen%20und%20die%20L%C3%A4nge%20der%20Liste%20mit%20Wicket%20an%2C%20ohne%20dass%20ich%20die%20Liste%20zweimal%20erzeugen%20muss%3F%0D%0A%0D%0AF%C3%BCr%20die%20Liste%20w%C3%BCrde%20man%20ein%20LoadableDetachableModel%20benutzen%20und%20in%20load%28%29%20das%20Ergebnis%20zur%C3%BCckliefern.%0D%0Afinal%20Loadable" 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%2F01%2F03%2Fmodell-referenzen%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%2F01%2F03%2Fmodell-referenzen%2F&amp;title=Modell-Referenzen&amp;notes=Wie%20zeige%20ich%20eine%20Liste%20von%20Elementen%20und%20die%20L%C3%A4nge%20der%20Liste%20mit%20Wicket%20an%2C%20ohne%20dass%20ich%20die%20Liste%20zweimal%20erzeugen%20muss%3F%0D%0A%0D%0AF%C3%BCr%20die%20Liste%20w%C3%BCrde%20man%20ein%20LoadableDetachableModel%20benutzen%20und%20in%20load%28%29%20das%20Ergebnis%20zur%C3%BCckliefern.%0D%0Afinal%20Loadable" 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%2F01%2F03%2Fmodell-referenzen%2F&amp;t=Modell-Referenzen" 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%2F01%2F03%2Fmodell-referenzen%2F&amp;title=Modell-Referenzen" 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%2F01%2F03%2Fmodell-referenzen%2F&amp;title=Modell-Referenzen&amp;annotation=Wie%20zeige%20ich%20eine%20Liste%20von%20Elementen%20und%20die%20L%C3%A4nge%20der%20Liste%20mit%20Wicket%20an%2C%20ohne%20dass%20ich%20die%20Liste%20zweimal%20erzeugen%20muss%3F%0D%0A%0D%0AF%C3%BCr%20die%20Liste%20w%C3%BCrde%20man%20ein%20LoadableDetachableModel%20benutzen%20und%20in%20load%28%29%20das%20Ergebnis%20zur%C3%BCckliefern.%0D%0Afinal%20Loadable" title="Google Bookmarks"><img src="http://www.wicket-praxis.de/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
<div id="vgwpixel"></div><h3  class="related_post_title">Andere Beiträge</h3><ul class="related_post"><li>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>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>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/01/03/modell-referenzen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 4/31 queries in 0.024 seconds using disk: basic
Object Caching 569/591 objects using disk: basic

Served from: www.wicket-praxis.de @ 2012-02-06 20:32:49 -->
