> Given these subtle problems with this approach, I admit I'm warming to > the multiple extend/child idea.
im oposite - if i have X extends in a page, whose extend should be preferred (e.g: manipulating the head or a part outside of itself) ?
my override of onBeforeRender is secure from your point and IMHO more easy...
John Krasnay schrieb:
On Wed, Nov 07, 2007 at 11:31:12AM +0100, Mats Norén wrote:Is the above statement really true considering that by adding abstract methods to your page you defer the creation of the markup in just the same way as the new proposed solution? BasePage.java public BasePage() { addAbstract1("abstractId1"); addAbstract2("abstractId2); } public abstract addAbstract1(String abstractId1); public abstract addAbstract2(String abstractId2); BasePage.html <span wicket:id="abstractId1"/> <span wicket:id="abstractId2"/> What is the difference between that and doing abstract / implements?You've just illustrated one of the major problems with the panel-from-a-subclass approach: it's easy to get it wrong. In your example, addAbstract1 and addAbstract2 will be called in a class whose constructor has not yet been called. Consider: public DerivedPage extends BasePage { private String name; public DerivedPage(String name) { super(); this.name = name; } public abstract addAbstract1(String abstractId1) { add(new NamePanel(abstractId1, name)); } } This code is broken, since you're constructing NamePanel before name has been initialized. Someone later in this thread shows a better way to do this, by calling the overridable methods from onBeforeRender. But this is also tricky; because onBeforeRender can be called multiple times you must maintain a flag to ensure you only add your panels once. Given these subtle problems with this approach, I admit I'm warming to the multiple extend/child idea. jk --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
