All of them are implementations of the interface IModel.
Class Model is a basic implementation, that is almost just a 'data holder' so you can store an object in that model and get. The added value of this class is to forward to get and to set model object if the stored object is an other model (IModel).
Class PropertyModel is useful if you want to get / to set a property using property expression. See an example:
class Data {
private Integer data;
private String name;
/* getters and setters */
}
How to get and set data using the PropertyModel:
Data data = new Data();
data.setId(1);
data.setName("data entity");
IModel idModel = new PropertyModel(data, "id");
IModel nameModel = new PropertyModel(data, "name");
System.out.println(data.getId());
// prints '1'
System.out.println(idModel.getObject());
// prints '1'
System.out.println(data.getName);
// prints 'data entity'
System.out.println(nameModel.getObject());
// prints 'data entity'
data.setId(2);
nameModel.setObject("a new name");
System.out.println(data.getId());
// prints '2'
System.out.println(idModel.getObject());
// prints '2'
System.out.println(data.getName());
// prints 'a new name'
System.out.println(nameModel.getObject());
// prints 'a new name'
Class CompoundPropertyModel is useful if you want to propage properties to the components by their IDs. See an example (using the same class Data):
Java Code (MyPanel.java):
class MyPanel extends Panel {
public MyPanel(IModel<Data> model) {
super(new CompoundPropertyModel<Data>(model));
add(new Label("id"));
add(new Label("data"));
}
}
Markup (MyPanel.html):
<wicket:panel>
<span wicket:id="id">placeholer for id</span>
<span wicket:id="name">placeholer for id</span>
</wicket:panel>
Java Code using MyClass:
// in a Page, Panel or an other Component
Data data = new Data();
data.setId(3);
data.setName('my name');
add(new MyPanel(Model.of(data)));
Rendered output HTML (by the panel):
<span>3</span>
<span>my name</span>