On Sat, Apr 26, 2008 at 04:17:35AM -0700, John Patterson wrote:
> 
> Sorry, I did find a discussion which was related [1] which ended with Igor
> saying:
> 
> "yes, but its also easy to fix. Just don't call any overridible methods 
> inside constructors. And for everything else there is onbeforerender()"
> 
> If this is the recommended way to write extendible components I could add a
> wiki page because it is not very intuitive.
> 
> So to be clear, whenever building a component designed to be extendible:
> 
> 1 - Call all overridable methods from onBeforeRender()

This rule is too strict. Another way to avoid calling overridable
methods from the constructor is to use a model:

public abstract void BaseComponent extends Panel {

    protected abstract String getTitle();

    public BaseComponent(String id) {
        super(id);
        add(new Label("title", new AbstractReadOnlyModel() {
            public Object getObject() {
                return getTitle();
            }
        });
    }
}

This works because getObject() is not called until after the panel is
constructed (at render time, I believe).

jk

> 2 - Check that components are not added more than once
> 3 - call super.onBeforeRender()
> 
> Anything else to keep in mind?
> 
> Thanks,
> 
> John
> 
> [1]
> http://www.nabble.com/Re%3A-Jira-issue-moved-to-the-list%3A-constructors-and-init-of-components-p13569575.html
> 
> 
> 
> Martijn Dashorst wrote:
> > 
> > We have discussed this over and over on the list. Search the archives.
> > Short answer: NO.
> > 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Alternative-method-to-initialise-page-tp16742636p16911887.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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]

Reply via email to