|
Page Edited :
WICKET :
User code context
User code context has been edited by Martin Grigorov (Apr 13, 2008). Content:
There are three common contexts in Wicket from which user code may be called (numeration here implies the order in which code will be called):
public class MyPage extends WebPage ... public MyPage() { ... // 1 - page creation final Form form = new Form("form", model) { @Override protected void onSubmit() { // 2 - event handling (optional) }
@Override
protected void onBeforeRender() {
// 3 - rendering
super.onBeforeRender();
}
};
add(form);
}
Page creationPage creation means executing code in page constructor. Page creation occurs in two cases:
There are no restrictions on what you can do in page creation context. The common thing is to create components and models. Beware of calling overriden methods in constructor, since at the time overriden method is called in base class constructor, child class which overrides this method, is not fully constructed. If you call overriden methods in constructor anyway, make sure they do not use properties from child class. Event handlingEvent handling is a process of executing code in methods like onSubmit(), onClick() and the like. All these methods calls originates from implementations of IRequestListener interface (see IRequestListener subinterfaces for the full list of all possible callbacks). Event handling may happen as many times as event occurs (for example user produces some action). Normally event handling happens in another request than the one which created the page. Replacing panel in event handler public class MyPage extends WebPage ... public MyPage() { ... // note that panels use the same id add(new Link("feedback") { public void onClick() { MyPage.this.replace(new FeedbackPanel("mainPanel")); } }); add(new Link("about") { public void onClick() { MyPage.this.replace(new AboutPanel("mainPanel")); } }); } RenderingRendering is performed after page creation and event handling. It happens as many times as page or components (in case of ajax) is requested by browser. Whether rendering is performed in the same request as event handling depends on rendering strategy.
ModelsModel's methods are called by Wicket in some of the above contexts. Generally, you don't need to think when model methods are called and what rules apply unless you are writing some clever code inside a model. This example code shows in comments when model methods may be called: public class MyPage extends WebPage ... public MyPage() { ... final Model model = new Model() { public Object getObject() { // called on event handling and component rendering return super.getObject(); } public void setObject(final Serializable object) { // called on event handling super.setObject(object); } }; final TextField text = new TextField("text", model); } |
Unsubscribe or edit your notifications preferences
