<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Building a smart EntityModel</title>
	<atom:link href="http://wicketinaction.com/2008/09/building-a-smart-entitymodel/feed/" rel="self" type="application/rss+xml" />
	<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/</link>
	<description>A comprehensive guide for Java developers building Wicket-based web applications</description>
	<pubDate>Wed, 07 Jan 2009 00:05:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: ivaynberg</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-294</link>
		<dc:creator>ivaynberg</dc:creator>
		<pubDate>Mon, 15 Dec 2008 18:49:09 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-294</guid>
		<description>@Paul: I had to do a lot of refactoring in 1.4 to get this working correctly. Unfortunately I cannot port this back to 1.3 because it has production apps running on it that might depend on the functionality this changed.

It is pretty easy to set up a single-transaction-per-request pattern in wicket. It is not as granular as a transaction for the form submit, but it should still work.

&lt;pre lang="java"&gt;
public class WicketRequestCycle extends WebRequestCycle
{
    private TransactionStatus txn;

    @Dependency
    private PlatformTransactionManager txm;

    public WicketRequestCycle(WebApplication application, WebRequest request, Response response)
    {
        super(application, request, response);
    }

    @Override
    protected void onBeginRequest()
    {
        txn = txm.getTransaction(new DefaultTransactionDefinition());
        super.onBeginRequest();
    }

    @Override
    protected void onEndRequest()
    {
        super.onEndRequest();
        if (txn != null)
        {
            txm.commit(txn);
            txn = null;
        }
    }

    @Override
    public Page onRuntimeException(Page page, RuntimeException e)
    {
        if (txn != null)
        {
            txm.rollback(txn);
            txn = null;
        }
        return super.onRuntimeException(page, e);
    }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@Paul: I had to do a lot of refactoring in 1.4 to get this working correctly. Unfortunately I cannot port this back to 1.3 because it has production apps running on it that might depend on the functionality this changed.</p>
<p>It is pretty easy to set up a single-transaction-per-request pattern in wicket. It is not as granular as a transaction for the form submit, but it should still work.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color:#7f0055;font-weight:bold">public</span> <span style="color:#7f0055;font-weight:bold">class</span> WicketRequestCycle <span style="color:#7f0055;font-weight:bold">extends</span> WebRequestCycle
<span style="color: #000;">&#123;</span>
    <span style="color:#7f0055;font-weight:bold">private</span> TransactionStatus txn;
&nbsp;
    @Dependency
    <span style="color:#7f0055;font-weight:bold">private</span> PlatformTransactionManager txm;
&nbsp;
    <span style="color:#7f0055;font-weight:bold">public</span> WicketRequestCycle<span style="color: #000;">&#40;</span>WebApplication application, WebRequest request, Response response<span style="color: #000;">&#41;</span>
    <span style="color: #000;">&#123;</span>
        <span style="color:#7f0055;font-weight:bold">super</span><span style="color: #000;">&#40;</span>application, request, response<span style="color: #000;">&#41;</span>;
    <span style="color: #000;">&#125;</span>
&nbsp;
    @Override
    <span style="color:#7f0055;font-weight:bold">protected</span> <span style="color:#7f0055;font-weight:bold">void</span> onBeginRequest<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>
    <span style="color: #000;">&#123;</span>
        txn <span style="color: #339933;">=</span> txm.<span style="color: #006633;">getTransaction</span><span style="color: #000;">&#40;</span><span style="color:#7f0055;font-weight:bold">new</span> DefaultTransactionDefinition<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>;
        <span style="color:#7f0055;font-weight:bold">super</span>.<span style="color: #006633;">onBeginRequest</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>;
    <span style="color: #000;">&#125;</span>
&nbsp;
    @Override
    <span style="color:#7f0055;font-weight:bold">protected</span> <span style="color:#7f0055;font-weight:bold">void</span> onEndRequest<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>
    <span style="color: #000;">&#123;</span>
        <span style="color:#7f0055;font-weight:bold">super</span>.<span style="color: #006633;">onEndRequest</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>;
        <span style="color:#7f0055;font-weight:bold">if</span> <span style="color: #000;">&#40;</span>txn <span style="color: #339933;">!=</span> <span style="color:#7f0055;font-weight:bold">null</span><span style="color: #000;">&#41;</span>
        <span style="color: #000;">&#123;</span>
            txm.<span style="color: #006633;">commit</span><span style="color: #000;">&#40;</span>txn<span style="color: #000;">&#41;</span>;
            txn <span style="color: #339933;">=</span> <span style="color:#7f0055;font-weight:bold">null</span>;
        <span style="color: #000;">&#125;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    @Override
    <span style="color:#7f0055;font-weight:bold">public</span> Page onRuntimeException<span style="color: #000;">&#40;</span>Page page, <span style="color:#7f0055;font-weight:bold">RuntimeException</span> e<span style="color: #000;">&#41;</span>
    <span style="color: #000;">&#123;</span>
        <span style="color:#7f0055;font-weight:bold">if</span> <span style="color: #000;">&#40;</span>txn <span style="color: #339933;">!=</span> <span style="color:#7f0055;font-weight:bold">null</span><span style="color: #000;">&#41;</span>
        <span style="color: #000;">&#123;</span>
            txm.<span style="color: #006633;">rollback</span><span style="color: #000;">&#40;</span>txn<span style="color: #000;">&#41;</span>;
            txn <span style="color: #339933;">=</span> <span style="color:#7f0055;font-weight:bold">null</span>;
        <span style="color: #000;">&#125;</span>
        <span style="color:#7f0055;font-weight:bold">return</span> <span style="color:#7f0055;font-weight:bold">super</span>.<span style="color: #006633;">onRuntimeException</span><span style="color: #000;">&#40;</span>page, e<span style="color: #000;">&#41;</span>;
    <span style="color: #000;">&#125;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Mogren</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-293</link>
		<dc:creator>Paul Mogren</dc:creator>
		<pubDate>Mon, 15 Dec 2008 16:42:29 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-293</guid>
		<description>@Igor 
In reference to comment #18, 
I'm trying to find a way to achieve this in Wicket 1.3, and having a hard time. It appears that onSubmit() is not called within form.process(), and a lot of the methods I might try to override for this are declared final. Can you (or anyone) suggest where I can begin and end the transaction? THanks</description>
		<content:encoded><![CDATA[<p>@Igor<br />
In reference to comment #18,<br />
I&#8217;m trying to find a way to achieve this in Wicket 1.3, and having a hard time. It appears that onSubmit() is not called within form.process(), and a lot of the methods I might try to override for this are declared final. Can you (or anyone) suggest where I can begin and end the transaction? THanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Persistenz für den Feedreader - rattlab.net</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-108</link>
		<dc:creator>Persistenz für den Feedreader - rattlab.net</dc:creator>
		<pubDate>Tue, 28 Oct 2008 20:01:43 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-108</guid>
		<description>[...] Das NewsModel ist nicht von LoadableDetachableModel abgeleitet, da wir keinen schreibenden Zugriff auf das zu speichernde Objekt hätten, sondern dieses immer über load() geladen werden müsste. Dennoch ist die Model-Klasse recht einfach und übersichtlich. Es speichert die ID und die News selbst, beim Speichern in der Session wird die News aber nicht serialisiert. Werden die Daten wieder aus der Session geholt (z.B. durch ein Neu Laden der Seite), so wird die News anhand der ID erneut aus der Datenbank geladen. Eine allgemein gehaltenere Version eines solchen Models beschreibt Igor Vaynberg, einer der Wicket-Mitentwickler, im Blogeintrag &#8220;Building a smart EntityModel&#8221;. [...]</description>
		<content:encoded><![CDATA[<p>[...] Das NewsModel ist nicht von LoadableDetachableModel abgeleitet, da wir keinen schreibenden Zugriff auf das zu speichernde Objekt hätten, sondern dieses immer über load() geladen werden müsste. Dennoch ist die Model-Klasse recht einfach und übersichtlich. Es speichert die ID und die News selbst, beim Speichern in der Session wird die News aber nicht serialisiert. Werden die Daten wieder aus der Session geholt (z.B. durch ein Neu Laden der Seite), so wird die News anhand der ID erneut aus der Datenbank geladen. Eine allgemein gehaltenere Version eines solchen Models beschreibt Igor Vaynberg, einer der Wicket-Mitentwickler, im Blogeintrag &#8220;Building a smart EntityModel&#8221;. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jörn Zaefferer</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-27</link>
		<dc:creator>Jörn Zaefferer</dc:creator>
		<pubDate>Mon, 06 Oct 2008 13:33:29 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-27</guid>
		<description>Okay, that makes sense. Thanks for clarifying.</description>
		<content:encoded><![CDATA[<p>Okay, that makes sense. Thanks for clarifying.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ivaynberg</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-26</link>
		<dc:creator>ivaynberg</dc:creator>
		<pubDate>Mon, 06 Oct 2008 04:19:11 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-26</guid>
		<description>@Jörn: We want the entity loaded, updated, and saved all in the same transaction. onSubmit() is called after wicket has already applied user inputs to the model object, at that point you would have to session.merge() your changes instead of having them transparently persisted.</description>
		<content:encoded><![CDATA[<p>@Jörn: We want the entity loaded, updated, and saved all in the same transaction. onSubmit() is called after wicket has already applied user inputs to the model object, at that point you would have to session.merge() your changes instead of having them transparently persisted.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jörn Zaefferer</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-20</link>
		<dc:creator>Jörn Zaefferer</dc:creator>
		<pubDate>Sun, 05 Oct 2008 21:38:15 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-20</guid>
		<description>Whats the adavantage of overriding process and doing a rollback when super.process returns false, instead of just overriding submit? Submit gets called only when the submit is valid, so no transaction gets started unless the submit is actually valid.</description>
		<content:encoded><![CDATA[<p>Whats the adavantage of overriding process and doing a rollback when super.process returns false, instead of just overriding submit? Submit gets called only when the submit is valid, so no transaction gets started unless the submit is actually valid.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ivaynberg</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-19</link>
		<dc:creator>ivaynberg</dc:creator>
		<pubDate>Sat, 04 Oct 2008 16:27:24 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-19</guid>
		<description>@Marcell: Sure. I can do the same thing with the Session and a uuid token stored in the model. The big advantage of just using the model is that it is its own conversational scope. Eg, the user does whatever they need and the conversation ends, then the user presses back button 4 times and tries to do something - error because conversation has already been closed. This wouldnt happen with the model because it would be stored with the page and retrieved again.</description>
		<content:encoded><![CDATA[<p>@Marcell: Sure. I can do the same thing with the Session and a uuid token stored in the model. The big advantage of just using the model is that it is its own conversational scope. Eg, the user does whatever they need and the conversation ends, then the user presses back button 4 times and tries to do something - error because conversation has already been closed. This wouldnt happen with the model because it would be stored with the page and retrieved again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcell</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-18</link>
		<dc:creator>Marcell</dc:creator>
		<pubDate>Sat, 04 Oct 2008 09:36:38 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-18</guid>
		<description>@Igor: When I mean to use the conversational context you wouldn't store the transient Model in the EntityModel. You probably would do at detach and attach:

if (entity != null) {
  if (if (entity.getId() != null) {
    ...
  } else {
    Context.getConversationContext().set(this.getClass().getName()+"#entity",entity);
  }
}

And at getObject():

if (entity == null) {
  if (id != null) {
    ...
  } else {
    entity = (T) Context.getConversationContext().get(this.getClass().getName()+"#entity");
  }
}</description>
		<content:encoded><![CDATA[<p>@Igor: When I mean to use the conversational context you wouldn&#8217;t store the transient Model in the EntityModel. You probably would do at detach and attach:</p>
<p>if (entity != null) {<br />
  if (if (entity.getId() != null) {<br />
    &#8230;<br />
  } else {<br />
    Context.getConversationContext().set(this.getClass().getName()+&#8221;#entity&#8221;,entity);<br />
  }<br />
}</p>
<p>And at getObject():</p>
<p>if (entity == null) {<br />
  if (id != null) {<br />
    &#8230;<br />
  } else {<br />
    entity = (T) Context.getConversationContext().get(this.getClass().getName()+&#8221;#entity&#8221;);<br />
  }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ivaynberg</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-17</link>
		<dc:creator>ivaynberg</dc:creator>
		<pubDate>Sat, 04 Oct 2008 04:31:15 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-17</guid>
		<description>@Iman: its not really a workaround, more of a way you build your app. The problem here is that the model is shared between multiple pages, so the solution is to eliminate multiple pages. Instead of navigation consisting of going from page to page you can instead keep the user on the same page and accomplish the same navigation by swapping out the "content" panel.

eg

&lt;pre lang="java"&gt;
class ViewUserPanel extends Panel {
  public ViewUserPanel(String id, IModel user) {
      add(new Link("edit") {
         onclick() {
             onEditUser(getModel());
         }
      });
   }

   private void onEditUser() {
        replaceWith(new EditUserPanel(getId(), getModel()));
   }
}
&lt;/pre&gt;

So, instead of calling setResponsePage(new EditUserPage()) you swap the panel...</description>
		<content:encoded><![CDATA[<p>@Iman: its not really a workaround, more of a way you build your app. The problem here is that the model is shared between multiple pages, so the solution is to eliminate multiple pages. Instead of navigation consisting of going from page to page you can instead keep the user on the same page and accomplish the same navigation by swapping out the &#8220;content&#8221; panel.</p>
<p>eg</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color:#7f0055;font-weight:bold">class</span> ViewUserPanel <span style="color:#7f0055;font-weight:bold">extends</span> <span style="color:#7f0055;font-weight:bold">Panel</span> <span style="color: #000;">&#123;</span>
  <span style="color:#7f0055;font-weight:bold">public</span> ViewUserPanel<span style="color: #000;">&#40;</span><span style="color:#7f0055;font-weight:bold">String</span> id, IModel user<span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
      add<span style="color: #000;">&#40;</span><span style="color:#7f0055;font-weight:bold">new</span> Link<span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;edit&quot;</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
         onclick<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
             onEditUser<span style="color: #000;">&#40;</span>getModel<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>;
         <span style="color: #000;">&#125;</span>
      <span style="color: #000;">&#125;</span><span style="color: #000;">&#41;</span>;
   <span style="color: #000;">&#125;</span>
&nbsp;
   <span style="color:#7f0055;font-weight:bold">private</span> <span style="color:#7f0055;font-weight:bold">void</span> onEditUser<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
        replaceWith<span style="color: #000;">&#40;</span><span style="color:#7f0055;font-weight:bold">new</span> EditUserPanel<span style="color: #000;">&#40;</span>getId<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>, getModel<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>;
   <span style="color: #000;">&#125;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>So, instead of calling setResponsePage(new EditUserPage()) you swap the panel&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Iman Rahmatizadeh</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/#comment-16</link>
		<dc:creator>Iman Rahmatizadeh</dc:creator>
		<pubDate>Sat, 04 Oct 2008 04:22:56 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-16</guid>
		<description>@Igor: I wasn't aware of any workaround with panels. As I use panels extensively in my app, would you care to elaborate how it would help in this scenario ?</description>
		<content:encoded><![CDATA[<p>@Igor: I wasn&#8217;t aware of any workaround with panels. As I use panels extensively in my app, would you care to elaborate how it would help in this scenario ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
