...
Wicket provides the detachability hooks and will automatically detatch detach the default model of each component. However its common to use more than a single IModel
implementation per component especially when using nested or chaining models. In this case the developer is responsible for registering their custom models to participate in the detachment process.
...
Code Block |
---|
public class MyPanel extends Panel { private final DetatchableModelA detachableModelA; public MyPanel (String id) { super(id); this.detachableModelA = new DetachableModelA(); add (new CustomFormPanel ("formPanel", new CListModelFromA (this.detachableModelA))); } @Override public void detach() { // remember to call the parent detach logic super.detatchdetach(); this.detachableModelA.detatchdetach(); } } |
Here you see that the DetachableModelA
instance is created in the MyPanel
constructor and then passed in as the inner model to the CListModelFromA
model which will load a List<C>
instances based on the details of the A
instance contained in the model. Because the this.detachableModelA
instance could possibly be shared like this in many sub component models its important that the CListModelFromA
implementation does not try and call detach()
on it but rather leave the detachment to occur in the same scope that the model was instantiated. In this case the detachment is done in the MyPanel.detach
.
...
Code Block |
---|
class LoadablePersonModel extends LoadableDetachableModelLoadableDetachableModel<Person> { Long id; LoadablePersonModel(Long id) { this.id = id; } @Override protected ObjectPerson load() { return DataManager.getPersonFromDatabase(id); } } |
...