All of them are implementations of the IModel interface.
The Model class is a basic implementation, which is almost a "data holder", so you can save the object in this model and get it. The added value of this class is to forward, to receive and set the model object, if the stored object is another model (IModel).
The PropertyModel class is useful if you want to get / set a property using a property expression. Example:
class Data { private Integer data; private String name; }
How to get and set data using 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'
The CompoundPropertyModel class is useful if you want to skip component properties by their identifiers. See Example (using the same Data class):
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)));
HTML output is displayed (in the panel):
<span>3</span> <span>my name</span>
source share