Difference between compound model and propertymodel in wicket
Propertymodel and compoundPropertyModel does same job of binding the data from UI ( through components like text box ,dropdowns and radio choice) to object (variable in object ). Both can bind data in either ways . that is from object to UI and UI to object.
Difference is between them is the way it does that job . In Propertymodel , while creating itself we have to tell which variable in the object Propertymodel refers to . This syntax of PropertyModel
public PropertyModel(final Object modelObject, final String expression)
But in CompoundPropertyModel we just refer the whole object when we create CompoundPropertyModel . While binding to any UI compoent we will tell which variable it refers to through bind method .
This makes coding simple , reusable and reduce number of line of code . This also reduces memory size and share model with children.
File : Employee.java
private String name;
private String id;
void setName(String name)
this.name = name;
void setId(String id)
this.id = id;
With PropertyModel we will write code as below
PropertyModel employeeNameModel = new PropertyModel(Employee, "name");
PropertyModel employeeIdModel = new PropertyModel(Employee, "id");
TextField nameField = new RequiredTextField("nameWicketId", employeeNameModel);
TextField idField = new RequiredTextField("idWicketId", employeeIdModel);
With CompoundPropertyModel we will write code as below
CompoundPropertyModel employeeModel = new CompoundPropertyModel(Employee);
TextField nameField = new RequiredTextField("nameWicketId", employeeModel.bind("name"));
TextField idField = new RequiredTextField("idWicketId", employeeModel.bind("id"));