basically IModel has a getObject(Component c) and setObject(Component c, Object value)
notice the Component argument.
the compoundpropertymodel does this
getObject(Component c) {
return object's property with name c.id
}
and setter does the reverse
the bound version lets you bind components to property paths rather then always using direct translation of component's id to the property name that the compound model uses
so you can say
BoundCompoundPropertyModel m=new .....
Form form=new Form("form", m);
TextField tf=new TextField("name");
form.add(tf);
m.bind(tf, "firstName");
so now the textfield is bound to the firstName property of whatever object is in the bound model.
hope this clears things up a bit
usage examples are also wrong, the advantage of the compound models are that you dont have to set them for every form component because they are inherited
lets say you have a User class that has getFirstName(), getLastName()
User user=getUser();
Form form=new Form("form", new CompoundPropertyModel(user));
form.add(new TextField("firstName"));
form.add(new TextField("lastName"));
notice i did not set any models on the textfield components because they will inherit the compound one from the form, and their ids will be used as property expressions, so i quickly bound the textfield to the first and last name properties.
-Igor
On 5/4/06, Bruno Borges <[EMAIL PROTECTED]> wrote:
Ooooops... sorry Igor.
But one question: the Javadoc says that the BoundCompoundPropertyModel uses the name (I understand here as the id) of a component as the property name it should use to set value on model.
So, I understand as:
add(new TextField("name", new BoundCompountPropertyModel(userBean)));
or...
add(new TextField("name", new CompountPropertyModel(userBean, "name")));
Am I right?On 5/4/06, Igor Vaynberg < [EMAIL PROTECTED]> wrote:what you want is a CompoundPropertyModel not the bound variant.
there is a searchbox on our wiki :)
http://www.wicket-wiki.org.uk/wiki/index.php/Models
-IgorOn 5/4/06, Bruno Borges <[EMAIL PROTECTED]> wrote:Isn't this code correct?class UserForm extends Form {User user = new User(); // POJO Bean<constructor> {}...}
BoundCompoundPropertyModel model = new BoundCompoundPropertyModel(user);
add(new TextField("name", model));
add(new TextField("email", model)); // Can I do this? Use the same model object for different properties?
<on submit> {String name = user.getName ();}
// Why name is still null ?
Am I missing something here? Where in the docs has some reference for Property Models ?
--
Bruno Borges
[EMAIL PROTECTED]
Sun Certified Java Programmer for 1.4
Sun Certified Web Component Developer for 1.4
--
Bruno Borges
[EMAIL PROTECTED]
Sun Certified Java Programmer for 1.4
Sun Certified Web Component Developer for 1.4
