Hello,
I wonder why I should set a model to a form, if every form field just holds a
reference to the (same) model. Take a look at an example from Wicket in Action
(page 91):
public class MyForm extends Form {
public MyForm(String id) {
super(id);
Customer customer = new Customer();
setModel(new Model(customer)); // Why?
add(new TextField("name", new PropertyModel(customer, "name")));
add(new TextField("street",
new PropertyModel(customer, "address.street")));
}
protected void onSubmit() {
Customer customer = (Customer)getModelObject();
String street = customer.getAddress().getStreet();
// do something with the value oft the street property
}
}
Is there an advantage over keeping a reference to customer in MyForm like in
the following example?
public class MyForm extends Form {
private Customer customer = new Customer();;
public MyForm(String id) {
super(id);
//setModel(new Model(customer)); Not needed anymore.
add(new TextField("name", new PropertyModel(customer, "name")));
add(new TextField("street",
new PropertyModel(customer, "address.street")));
}
protected void onSubmit() {
//Customer customer = (Customer)getModelObject(); Not needed anymore.
String street = customer.getAddress().getStreet();
}
}
Thanks for enlightenment,
Christian
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]