Models are a important part of any wicket application. Despite it’s simple interface its a complex topic. But let’s start with some easy examples.
There is a simple model implementation, which can hold any data, which is serializable (see Model and detach (TODO)). This implementation implements two methods from the IModel interface for interacting with the model value.
IModel<String> message = Model.of("any message");
message.setObject("current time: " + new Date());
add(new Label("message", message));
This examples shows an easy way to create a model instance for a value and how the value can be changed afterwards. The Label component accepts any serializable model value (not only strings, see Converter).
As any page contains mainly components and models. Most data is stored in models, it is important to know, that models are detached after the page is rendered (see Request Cycle). to remove anything from the page which is not needed anymore.