BoundCompoundPropertyModel not setting values

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

BoundCompoundPropertyModel not setting values

Bruno Borges
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
[hidden email]
Sun Certified Java Programmer for 1.4
Sun Certified Web Component Developer for 1.4
Reply | Threaded
Open this post in threaded view
|

Re: BoundCompoundPropertyModel not setting values

Igor Vaynberg-2
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

-Igor


On 5/4/06, Bruno Borges <[hidden email]> 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
[hidden email]
Sun Certified Java Programmer for 1.4
Sun Certified Web Component Developer for 1.4

Reply | Threaded
Open this post in threaded view
|

Re: BoundCompoundPropertyModel not setting values

Bruno Borges
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 <[hidden email]> wrote:
what you want is a CompoundPropertyModel not the bound variant.

there is a searchbox on our wiki :)

<a href="http://www.wicket-wiki.org.uk/wiki/index.php/Models" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.wicket-wiki.org.uk/wiki/index.php/Models

-Igor



On 5/4/06, Bruno Borges <[hidden email]> 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
[hidden email]
Sun Certified Java Programmer for 1.4
Sun Certified Web Component Developer for 1.4




--
Bruno Borges
[hidden email]
Sun Certified Java Programmer for 1.4
Sun Certified Web Component Developer for 1.4
Reply | Threaded
Open this post in threaded view
|

Re: BoundCompoundPropertyModel not setting values

Eelco Hillenius
The idea is that you set a Compound/BoundCompoundPropertyModel on the
parent (or further up the hierarchy) of these components.

setModel(new (Bound)CompoundPropertyModel(userBean));
add(new TextField("name"));

Bound and the normal CompoundPropertyModel do not differ much from
each other, except that the Bound variant *additionally* gives you the
option of binding to another property of the component id. That's
handy when you have say 10 components to add, and just one of them has
a property name that differs from the component id you want to use. In
that case, you would do:

BoundCompoundPropertyModel m = new BoundCompoundPropertyModel(userBean);
setModel(m);
TextField t = new TextField("someid");
add(t);
m.bind(t, "name");

The equivilant of what you want without these types of models is the
plain property model:

add(new TextField("someid", new PropertyModel(userBean, "name"));



Eelco

>
>  So, I understand as:
>
> add(new TextField("name", new
> BoundCompountPropertyModel(userBean)));
>
> or...
>
> add(new TextField("name", new CompountPropertyModel(userBean, "name")));
>
> Am I right?
>


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Wicket-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/wicket-user
Reply | Threaded
Open this post in threaded view
|

Re: BoundCompoundPropertyModel not setting values

Igor Vaynberg-2
In reply to this post by Bruno Borges
no thats the compound one.

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 <[hidden email]> 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 <[hidden email]> wrote:
what you want is a CompoundPropertyModel not the bound variant.

there is a searchbox on our wiki :)

<a href="http://www.wicket-wiki.org.uk/wiki/index.php/Models" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.wicket-wiki.org.uk/wiki/index.php/Models

-Igor



On 5/4/06, Bruno Borges <[hidden email]> 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
[hidden email]
Sun Certified Java Programmer for 1.4
Sun Certified Web Component Developer for 1.4




--
Bruno Borges
[hidden email]
Sun Certified Java Programmer for 1.4
Sun Certified Web Component Developer for 1.4