Wicket: Where to add components? Constructor? Or onBeforeRender?

I am new to wickets. It may just be my ignorance of the Wicket life cycle, so please enlighten me! I understand that Wicket WebPage objects are created once and then serialized. This led to confusion for me, see below.

I currently have a template class that I intend to subclass. I followed an example in Wicket docs, demonstrating how to override template behavior in a subclass:

protected void onBeforeRender() {
        add(new Label("title", getTitle()));

        super.onBeforeRender();
}

protected String getTitle() {
        return "template";
}

Subclass:

protected String getTitle() {
        return "Home";
}

. , " " . , onBeforeRender() , ? , , onBeforeRender(). Wicket , , , .

, , onBeforeRender()?

+5
3

, Page, onInitialize , , ( component.getPage() doesn 't return null).

- addOrReplace() add.

, Model . :

public abstract class BasePage extends WebPage {
    public BasePage() {
        add(new Label("title", new PropertyModel<String>(this, "title")));
    }
    public abstract String getTitle();
}

PropertyModel , .

+10

, , . , () . ( ) .

+4

The onBeforeRender method is useful for handling a visible component or managing a model.

0
source

All Articles