I want to create an ajaxcheckbox without wiring it to a class attribute using propertymodel. Why does the code in the example not work? The boolean value doesnt change when the user checks or unchecks the checkbox.
boolean show = false;
AjaxCheckBox showBox = new AjaxCheckBox("showBox", new Model<Boolean>(show)){
//onUpdate stuff
};
The boolean value will not change because the
showBoxdoes not have a reference to the original variableshow. You just initialized theshowBoxmodel with false. The code you have there is equivalent to:If you want to access the model value of the
showBoxyou can usegetModelObject(), which will return the boolean value stored in theAjaxCheckBox‘s model.Models are complex in wicket – but very powerful.
To illustrate further,
Modelkeeps its own reference to a value.PropertyModelkeeps a reference to a different object, and then stores the value in the property of that object. Look at the source code ofModeland you’ll see it is very simple.