Pages Navigation Menu

Coding is much easier than you think

Difference between compound model and propertymodel in wicket

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

 

class Employee
{
  private String name;
  private String id; 
  void setName(String name)
  {
    this.name = name;
  }
  String getName()
  {
    return name;
  }
  void setId(String id)
  {
    this.id = id;
  }
  String getId()
  {
    return 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"));

 

About Gokul


I am very much interested in android and Wicket framework. A core android developer and working in android native app development and responsive web mobile design. I have also worked in wicket fame work and java web development. I will keep on updating you about android and wicket framework and answer your query.