The problem lies in the references. In your first version, you kept a
direct reference to the model object passed in at construction time.
At that moment, the property model keeps a reference to that object.

When you changed the Model of the panel, the property model was not
notified: there is no way for the property model to know the model has
changed: it kept a private reference to that object. So when you
called setModel() on your panel, you should have 'rebound' the label
with a new propertymodel pointing to the new object of the new model.

In my first reply, I gave the property model a reference to the panel
model instead, so that the model is nested. This allows the panel
model to receive a new object, and have that reflect in the property
model too: it will use the panel model to lookup the model object. But
in your case, you explicitly replace the model of the panel, not the
model object. So that is again a new reference, and the propertymodel
has no notion of that reference. Basically it is the same scenario as
the first one.

The final one does the look up explicitly: the getObject() method asks
the panel for the model, so any change in references is taken care of.

I hope this is a bit more clear... talking about models and objects
and nesting them makes my head hurt so I can understand that it may be
hard to grasp.

If you want a better understanding, try to draw a picture with
references and objects and see how they interact.

Martijn

On 6/28/07, Pieter Cogghe <[EMAIL PROTECTED]> wrote:
> Thanks, that works. I really didn't know what I did wrong, nut I understand
> the reasoning behind it.
>
> 2007/6/28, Martijn Dashorst <[EMAIL PROTECTED] >:
> >
> > On 6/28/07, Martijn Dashorst < [EMAIL PROTECTED]> wrote:
> > > new PropertyModel(model, "foo")
> >
> > erhm...
> >
> > not quite there yet... You should also notify the property model in
> > the setModel of your panel.
> >
> > In this case you have a push type of model binding. It usually is a
> > better model to adopt a pull type model.
> >
> > for instance, replace PropertyModel with:
> >
> > new Model() {
> >     public Object getObject(Component c) {
> >         return
> ((FooObject)MyPanel.this.getModelObject()).getMyProperty();
> >     }
> > }
> >
> > This will always update, and is refactor safe.
> >
> > Martijn
> >
> >
> > --
> > Wicket joins the Apache Software Foundation as Apache Wicket
> > Join the wicket community at irc.freenode.net: ##wicket
> > Wicket 1.2.6 contains a very important fix. Download Wicket now!
> > http://wicketframework.org
> >
> >
> -------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> > _______________________________________________
> > Wicket-user mailing list
> > Wicket-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
>
>
>
> --
> Pieter Cogghe
> Ganzendries 186
> 9000 Gent
> 0487 10 14 21
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>


-- 
Wicket joins the Apache Software Foundation as Apache Wicket
Join the wicket community at irc.freenode.net: ##wicket
Wicket 1.2.6 contains a very important fix. Download Wicket now!
http://wicketframework.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to