<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Wicket do&#8217;s and don&#8217;ts</title>
	<atom:link href="http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/</link>
	<description>Keep updated on what we&#039;re doing!</description>
	<lastBuildDate>Wed, 10 Mar 2010 09:00:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Frank Silbermann</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-924</link>
		<dc:creator>Frank Silbermann</dc:creator>
		<pubDate>Wed, 21 Oct 2009 14:28:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-924</guid>
		<description>Erik responded:  &quot;Don&#039;t use this technique before you have tried to use panel composition.&quot;

Well, I _am_ composing panels; the issue is the kind of glue I should use for attaching the panels within the page (in lieu of calling abstract methods from my constructor).  What method of assembling panels do you have in mind when you refer to &quot;panel composition&quot;?

I suppose one way is to assemble the panels in each page independently; the common panels are reused, but if 50 pages all use the same panel in the same place, I&#039;d be repeating that

    &quot;add( new Panel...);&quot;

command in 50 pages.  And, I&#039;d have to repeat the HTML containing the panel&#039;s wicket-id 50 times.  Not good.

Another approach we&#039;ve discussed is to have the base page assemble the common panels along with dummy panels, and to have the sub-page replace the panels that vary.  The sub-page programmer has to look at the base page documentation or code to learn the panels that should be replaced and the variables containing each respective wicket-id.  Is this what you mean by &quot;panel composition&quot;?

Suppose I move the base page&#039;s component tree construction out of the constructor into the method: 

     private void assembleComponents() { ... 

and add the property: 

    private boolean componentsAssembled = false;

Then I could add:

    @Override 
    void onBeforeRender() {
         if ( !componentsAssembled ) {
             assembleComponents();
             componentsAssembled = true;
         }
         super.onBeforeRender();  // Or whatever else I might have put into this method
    }

Then component construction would wait until the properties in both the parent and the subclass had been set, and I&#039;d no longer have a problem with calling abstract methods from the constructor.  Abstract methods would still tell the subclass what it needed to implement, and each abstract method would provide the proper wicket-id.

Do you see any disadvantages to this approach?  I don&#039;t think additional boolean test in &quot;onBeforeRender()&quot; is computationally significant, and it would not prevent me from adding any additional on-before-render tasks.

If it is a good approach, I wonder why the Wicket designers did not create an overrideable called-once-after-object-construction method in the Component class, and tell developers that this is where the component tree should be created.</description>
		<content:encoded><![CDATA[<p>Erik responded:  &#8220;Don&#8217;t use this technique before you have tried to use panel composition.&#8221;</p>
<p>Well, I _am_ composing panels; the issue is the kind of glue I should use for attaching the panels within the page (in lieu of calling abstract methods from my constructor).  What method of assembling panels do you have in mind when you refer to &#8220;panel composition&#8221;?</p>
<p>I suppose one way is to assemble the panels in each page independently; the common panels are reused, but if 50 pages all use the same panel in the same place, I&#8217;d be repeating that</p>
<p>    &#8220;add( new Panel&#8230;);&#8221;</p>
<p>command in 50 pages.  And, I&#8217;d have to repeat the HTML containing the panel&#8217;s wicket-id 50 times.  Not good.</p>
<p>Another approach we&#8217;ve discussed is to have the base page assemble the common panels along with dummy panels, and to have the sub-page replace the panels that vary.  The sub-page programmer has to look at the base page documentation or code to learn the panels that should be replaced and the variables containing each respective wicket-id.  Is this what you mean by &#8220;panel composition&#8221;?</p>
<p>Suppose I move the base page&#8217;s component tree construction out of the constructor into the method: </p>
<p>     private void assembleComponents() { &#8230; </p>
<p>and add the property: </p>
<p>    private boolean componentsAssembled = false;</p>
<p>Then I could add:</p>
<p>    @Override<br />
    void onBeforeRender() {<br />
         if ( !componentsAssembled ) {<br />
             assembleComponents();<br />
             componentsAssembled = true;<br />
         }<br />
         super.onBeforeRender();  // Or whatever else I might have put into this method<br />
    }</p>
<p>Then component construction would wait until the properties in both the parent and the subclass had been set, and I&#8217;d no longer have a problem with calling abstract methods from the constructor.  Abstract methods would still tell the subclass what it needed to implement, and each abstract method would provide the proper wicket-id.</p>
<p>Do you see any disadvantages to this approach?  I don&#8217;t think additional boolean test in &#8220;onBeforeRender()&#8221; is computationally significant, and it would not prevent me from adding any additional on-before-render tasks.</p>
<p>If it is a good approach, I wonder why the Wicket designers did not create an overrideable called-once-after-object-construction method in the Component class, and tell developers that this is where the component tree should be created.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik van Oosten</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-918</link>
		<dc:creator>Erik van Oosten</dc:creator>
		<pubDate>Wed, 21 Oct 2009 07:43:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-918</guid>
		<description>Hi Frank,

&gt; Markup inheritance is not a good solution IMAO, as it allows sub-pages to develop only a single part of the parent page.

Wicket is no silver bullet :)   I agree, you have to live with this limitation. But no despair, composition with panels is another technique that works very well.
One more note: Wicket 1.5 will allow multiple extension points for sub-pages.

&gt; Also, it wastefully forces the sub-page to have its own HTML file when all you’re trying to do is to insert into predetermined places a few panels that already contain their own HTML.

Well actually, I was saying it is wasteful to /replace/ components that were already added by the parent page. It is acceptable (within limits) to add components from sub-pages while the associated HTML is in the parent page. The wicket id to use can be given by a constant in the parent page. With Wicket 1.5 this kludge will no longer be necessary.

&gt; My motivation for using the abstract methods was:...

These are very good considerations. However, the underlying mechanism in flawed because you are using java ;)  Btw, I went through the same steps before I came to this conclusion.

&gt; What would be a better solution?

The solution is to step away from markup inheritance and only use it for the most basic HTML layout of the page. Instead you can use panel composition. (Note this is what I recommended in the article.)

&gt; It seems to me therefore to be a flaw in Wicket’s requirement that the page hierarchy of components be completely built during the page’s construction.

Strictly spoken, this is not the case. The component hierarchy must be complete before the render phase starts. Therefore you can also add components in an overridden Component#onBeforeRender. You&#039;ll need a flag to keep track if you already did this, or clear the currently present components. Also, you might want to override callOnBeforeRenderWhenInvisible. Don&#039;t use this technique before you have tried to use panel composition.</description>
		<content:encoded><![CDATA[<p>Hi Frank,</p>
<p>&gt; Markup inheritance is not a good solution IMAO, as it allows sub-pages to develop only a single part of the parent page.</p>
<p>Wicket is no silver bullet <img src='http://blog.jteam.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />    I agree, you have to live with this limitation. But no despair, composition with panels is another technique that works very well.<br />
One more note: Wicket 1.5 will allow multiple extension points for sub-pages.</p>
<p>&gt; Also, it wastefully forces the sub-page to have its own HTML file when all you’re trying to do is to insert into predetermined places a few panels that already contain their own HTML.</p>
<p>Well actually, I was saying it is wasteful to /replace/ components that were already added by the parent page. It is acceptable (within limits) to add components from sub-pages while the associated HTML is in the parent page. The wicket id to use can be given by a constant in the parent page. With Wicket 1.5 this kludge will no longer be necessary.</p>
<p>&gt; My motivation for using the abstract methods was:&#8230;</p>
<p>These are very good considerations. However, the underlying mechanism in flawed because you are using java <img src='http://blog.jteam.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   Btw, I went through the same steps before I came to this conclusion.</p>
<p>&gt; What would be a better solution?</p>
<p>The solution is to step away from markup inheritance and only use it for the most basic HTML layout of the page. Instead you can use panel composition. (Note this is what I recommended in the article.)</p>
<p>&gt; It seems to me therefore to be a flaw in Wicket’s requirement that the page hierarchy of components be completely built during the page’s construction.</p>
<p>Strictly spoken, this is not the case. The component hierarchy must be complete before the render phase starts. Therefore you can also add components in an overridden Component#onBeforeRender. You&#8217;ll need a flag to keep track if you already did this, or clear the currently present components. Also, you might want to override callOnBeforeRenderWhenInvisible. Don&#8217;t use this technique before you have tried to use panel composition.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank Silbermann</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-911</link>
		<dc:creator>Frank Silbermann</dc:creator>
		<pubDate>Tue, 20 Oct 2009 20:24:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-911</guid>
		<description>A follow-up to my previous question.  Is there any hook I could override in the base page that is called after the constructor returns but before the page&#039;s component hierarchy is matched to the HTML hierarchy of wicket-id tags?

I&#039;m thinking that if my base class overrode that method to call the &quot;CompleteThePage()&quot; method, then subclasses wouldn&#039;t have to worry about adding &quot;parent.CompleteThePage()&quot;  to the end of their constructors.</description>
		<content:encoded><![CDATA[<p>A follow-up to my previous question.  Is there any hook I could override in the base page that is called after the constructor returns but before the page&#8217;s component hierarchy is matched to the HTML hierarchy of wicket-id tags?</p>
<p>I&#8217;m thinking that if my base class overrode that method to call the &#8220;CompleteThePage()&#8221; method, then subclasses wouldn&#8217;t have to worry about adding &#8220;parent.CompleteThePage()&#8221;  to the end of their constructors.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank Silbermann</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-907</link>
		<dc:creator>Frank Silbermann</dc:creator>
		<pubDate>Tue, 20 Oct 2009 15:42:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-907</guid>
		<description>I see your point about constructors calling overridable methods.  It only works if the overriding method does not depend on anything that the subclass adds to the construction process.  (That&#039;s how I&#039;ve gotten away with this for so long.)  One might consider it a weakness in Java that nothing can be done in the subclass until the base class&#039; constructor has executed, but Java is what it is.  

It seems to me therefore to be a flaw in Wicket&#039;s requirement that the page hierarchy of components be completely built during the page&#039;s construction.  The parent page is only going to know about the components that are common to all the sub-pages.

Markup inheritance is not a good solution IMAO, as it allows sub-pages to develop only a single part of the parent page.  Also, it wastefully forces the sub-page to have its own HTML file when all you&#039;re trying to do is to insert into predetermined places a few panels that already contain their own HTML.

One alternative is to have the subclass replace dummy components that the parent page built -- but you condemn that, too, as wasteful and unmaintainable.

My motivation for using the abstract methods was:

(1) To ensure that no one tries to instantiate the base page (as its component hierarchy is incomplete), 
(2) So that writers of the sub-pages would know what components they needed to add, and
(3) So that writers of the sub-pages would not have to look at the base page&#039;s HTML file to discover those components&#039; wicket-IDs, nor would they have to examine the base-page&#039;s code to determine the container components to which the specialized sub-page components are to be added.

What would be a better solution?

Would you suggest putting into each base page an uncalled &quot;CompleteThePage()&quot; method -- which calls the abstract component-creation methods and adds the components to the component hierarchy in the proper places?

With this latter approach, we would then merely depend on the sub-page authors to to know that &quot;CompleteThePage()&quot; must be called at the end of their constructors (the compiler would still ensure that they instantiated the abstract methods it calls).

Of course, in a page hierarchy, the intermediate page constructor would have to call &quot;parent-page.CompleteThePage()&quot; -- to distinguish it from its own &quot;CompleteThePage()&quot; method that its children call in their constructors.

It really surprises me that the Wicket community has not discussed this issue already, and that Wicket developers would be satisfied with the weak and ugly &quot;mark-up inheritance.&quot;</description>
		<content:encoded><![CDATA[<p>I see your point about constructors calling overridable methods.  It only works if the overriding method does not depend on anything that the subclass adds to the construction process.  (That&#8217;s how I&#8217;ve gotten away with this for so long.)  One might consider it a weakness in Java that nothing can be done in the subclass until the base class&#8217; constructor has executed, but Java is what it is.  </p>
<p>It seems to me therefore to be a flaw in Wicket&#8217;s requirement that the page hierarchy of components be completely built during the page&#8217;s construction.  The parent page is only going to know about the components that are common to all the sub-pages.</p>
<p>Markup inheritance is not a good solution IMAO, as it allows sub-pages to develop only a single part of the parent page.  Also, it wastefully forces the sub-page to have its own HTML file when all you&#8217;re trying to do is to insert into predetermined places a few panels that already contain their own HTML.</p>
<p>One alternative is to have the subclass replace dummy components that the parent page built &#8212; but you condemn that, too, as wasteful and unmaintainable.</p>
<p>My motivation for using the abstract methods was:</p>
<p>(1) To ensure that no one tries to instantiate the base page (as its component hierarchy is incomplete),<br />
(2) So that writers of the sub-pages would know what components they needed to add, and<br />
(3) So that writers of the sub-pages would not have to look at the base page&#8217;s HTML file to discover those components&#8217; wicket-IDs, nor would they have to examine the base-page&#8217;s code to determine the container components to which the specialized sub-page components are to be added.</p>
<p>What would be a better solution?</p>
<p>Would you suggest putting into each base page an uncalled &#8220;CompleteThePage()&#8221; method &#8212; which calls the abstract component-creation methods and adds the components to the component hierarchy in the proper places?</p>
<p>With this latter approach, we would then merely depend on the sub-page authors to to know that &#8220;CompleteThePage()&#8221; must be called at the end of their constructors (the compiler would still ensure that they instantiated the abstract methods it calls).</p>
<p>Of course, in a page hierarchy, the intermediate page constructor would have to call &#8220;parent-page.CompleteThePage()&#8221; &#8212; to distinguish it from its own &#8220;CompleteThePage()&#8221; method that its children call in their constructors.</p>
<p>It really surprises me that the Wicket community has not discussed this issue already, and that Wicket developers would be satisfied with the weak and ugly &#8220;mark-up inheritance.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik van Oosten</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-742</link>
		<dc:creator>Erik van Oosten</dc:creator>
		<pubDate>Wed, 30 Sep 2009 11:21:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-742</guid>
		<description>Wille: indeed. Your &#039;do&#039; would be a nice addition. I try to do the same as well. I still use markup inheritence for the most basic page layout though.

Frank: Martin and LeChe gave the correct answer.

Dave, Nick: Thanks!</description>
		<content:encoded><![CDATA[<p>Wille: indeed. Your &#8216;do&#8217; would be a nice addition. I try to do the same as well. I still use markup inheritence for the most basic page layout though.</p>
<p>Frank: Martin and LeChe gave the correct answer.</p>
<p>Dave, Nick: Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LeChe</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-726</link>
		<dc:creator>LeChe</dc:creator>
		<pubDate>Fri, 25 Sep 2009 12:16:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-726</guid>
		<description>Frank,

I think the issue that Erik is referring to has to do with the general problem of calling abstract methods in any class&#039; constructor. Basically, you are leaking the reference to a incomplete object by doing that and any implementing class (that you might not be the author of) might incorrectly assume that object construction is finished!

The book &quot;Practical Java&quot; is a very good source for this (and similar) kinds of gotchas...

Regards,
Che</description>
		<content:encoded><![CDATA[<p>Frank,</p>
<p>I think the issue that Erik is referring to has to do with the general problem of calling abstract methods in any class&#8217; constructor. Basically, you are leaking the reference to a incomplete object by doing that and any implementing class (that you might not be the author of) might incorrectly assume that object construction is finished!</p>
<p>The book &#8220;Practical Java&#8221; is a very good source for this (and similar) kinds of gotchas&#8230;</p>
<p>Regards,<br />
Che</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-724</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Thu, 24 Sep 2009 16:31:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-724</guid>
		<description>Nice post.  
Just started using wicket for a project and I&#039;ll take note of your suggestions, especially the part about repeaters.</description>
		<content:encoded><![CDATA[<p>Nice post.<br />
Just started using wicket for a project and I&#8217;ll take note of your suggestions, especially the part about repeaters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: martin-g</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-703</link>
		<dc:creator>martin-g</dc:creator>
		<pubDate>Fri, 18 Sep 2009 17:00:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-703</guid>
		<description>Nice write-up Erik !

@Frank: check http://www.javapractices.com/topic/TopicAction.do?Id=215
I think this is what Erik meant</description>
		<content:encoded><![CDATA[<p>Nice write-up Erik !</p>
<p>@Frank: check <a href="http://www.javapractices.com/topic/TopicAction.do?Id=215" rel="nofollow">http://www.javapractices.com/topic/TopicAction.do?Id=215</a><br />
I think this is what Erik meant</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Bolton</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-699</link>
		<dc:creator>Dave Bolton</dc:creator>
		<pubDate>Fri, 18 Sep 2009 01:18:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-699</guid>
		<description>Great write up.  Coming from an arduous JSF project, we&#039;re looking at potentially using Wicket in the future, and it is this accumulated expert knowledge that gives real insight into a framework in use, rather than reading &quot;getting started&quot; guides which always gloss over this sort of thing.

Look forward to more posts like it.

Cheers,
D</description>
		<content:encoded><![CDATA[<p>Great write up.  Coming from an arduous JSF project, we&#8217;re looking at potentially using Wicket in the future, and it is this accumulated expert knowledge that gives real insight into a framework in use, rather than reading &#8220;getting started&#8221; guides which always gloss over this sort of thing.</p>
<p>Look forward to more posts like it.</p>
<p>Cheers,<br />
D</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank Silbermann</title>
		<link>http://blog.jteam.nl/2009/09/16/wicket-dos-and-donts/comment-page-1/#comment-698</link>
		<dc:creator>Frank Silbermann</dc:creator>
		<pubDate>Thu, 17 Sep 2009 14:24:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jteam.nl/?p=1015#comment-698</guid>
		<description>Goede Dag, Erik!

I don&#039;t understand your objection to components created by abstract methods, saying &quot;constructors should not call these.&quot;

Let&#039;s say I have a set of pages each with four quadrants (UpperLeft, UpperRight, LowerLeft, and LowerRight), and let&#039;s say that the UpperRight and LowerLeft are pretty constant across many pages of my application, but the UpperLeft and LowerRight panels vary independently page by page.  I would like to create a base page that deals with the two common panels once and for all.

So I create an HTML template with wicket IDs for the four panels in their place.  My abstract base page creates and adds all four panels.  However, for the UpperLeft and LowerRight panels (which vary across the sub-pages), the base page&#039;s constructor calls:

abstract Panel createUpperLeftPanel(String wicketID);

and

abstract Panel createLowerRightPanel(String wicketID);

in each case passing the actual wicket ID defined in the base page&#039;s HTML.

When developing the individual pages that inherit from my base page, I need no HTML file for the sub-pages -- they use the base page&#039;s HTML file.  In the sub-page definitions I can ignore the very existence of the UpperRight and LowerLeft boilerplate panels -- how is that for information hiding?  The only new HTML needed for the sub-pages is the HTML for the individual panels I instantiate when implementing the abstract methods.

When creating the page-specific panels, the sub-page definition doesn&#039;t even need to know the wicket IDs used by the base page  -- the abstract method provides it.  (If I change the wicket ID on the base page, as long as it passes the new ID to the abstract method, the sub-page does not break.)

So what&#039;s wrong with this pattern?</description>
		<content:encoded><![CDATA[<p>Goede Dag, Erik!</p>
<p>I don&#8217;t understand your objection to components created by abstract methods, saying &#8220;constructors should not call these.&#8221;</p>
<p>Let&#8217;s say I have a set of pages each with four quadrants (UpperLeft, UpperRight, LowerLeft, and LowerRight), and let&#8217;s say that the UpperRight and LowerLeft are pretty constant across many pages of my application, but the UpperLeft and LowerRight panels vary independently page by page.  I would like to create a base page that deals with the two common panels once and for all.</p>
<p>So I create an HTML template with wicket IDs for the four panels in their place.  My abstract base page creates and adds all four panels.  However, for the UpperLeft and LowerRight panels (which vary across the sub-pages), the base page&#8217;s constructor calls:</p>
<p>abstract Panel createUpperLeftPanel(String wicketID);</p>
<p>and</p>
<p>abstract Panel createLowerRightPanel(String wicketID);</p>
<p>in each case passing the actual wicket ID defined in the base page&#8217;s HTML.</p>
<p>When developing the individual pages that inherit from my base page, I need no HTML file for the sub-pages &#8212; they use the base page&#8217;s HTML file.  In the sub-page definitions I can ignore the very existence of the UpperRight and LowerLeft boilerplate panels &#8212; how is that for information hiding?  The only new HTML needed for the sub-pages is the HTML for the individual panels I instantiate when implementing the abstract methods.</p>
<p>When creating the page-specific panels, the sub-page definition doesn&#8217;t even need to know the wicket IDs used by the base page  &#8212; the abstract method provides it.  (If I change the wicket ID on the base page, as long as it passes the new ID to the abstract method, the sub-page does not break.)</p>
<p>So what&#8217;s wrong with this pattern?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
