You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by walnutmon <ju...@gmail.com> on 2008/10/24 15:57:46 UTC

Forcing property models to update

I have two panels, a view panel where you can look for news and an edit
panel.  The edit panel has a reference to a "news" object and all of it's
form elements have property models that use that object. 

When I pass a news object into the panel on creation all of the form
elements fill as expected.  However, if I set that object through a setter
in the panel class, the elements do not update.  My theory (which may be
wrong) is that the property model makes a defensive copy and therefore is
not linked to the object in the class.  If this is true, can I resend the
object to the property model?

If that's not true, any insight as to what I may be doing wrong?
-- 
View this message in context: http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20150693.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Forcing property models to update

Posted by Martijn Dashorst <ma...@gmail.com>.
Hmm, this requires a bit low level Java understanding (Wicket doesn't
have anything to do with it.

The underlying mechanism is the same as doing this:

public void foo2bar(String a) {
    a = "bar";
}

String b = "foo";
System.out.println("b is now: " + b);
foo2bar(b);
System.out.println("b is now: " + b);

What do you expect here? [1]

Now consider this:

public class Foo2Bar {
    private String text;
    public Foo2Bar(String t) {
        this.text = t;
    }
    public void setText(String t) {
        this.text = t;
    }
    public toString() {
        return text;
    }
}

String b = "foo";
Foo2Bar f2b = new Foo2Bar(b);
System.out.println("f2b is now: " + f2b);
b = "bar";
System.out.println("f2b is now: " + f2b);

What do you expect now? [2]

Java copies references to objects. When you modify the original
reference to point to another object, the copy doesn't get notified of
this change. THis is what is happening in your property models: you
give it a reference to a person, which is copied (the reference). Next
you modify the reference, but don't provide a way to notify the
property model that it should point to another person.

So to fix the second example: we need to notify our f2b instance that
the reference has changed, by calling setText

Martijn

[1] foo and foo
[2] "f2b is now: foo" and "f2b is now: foo"
On Tue, Oct 28, 2008 at 10:35 PM, walnutmon <ju...@gmail.com> wrote:
>
> I did as you said, and have the unit tests, and read the wiki on chaining
> models... something still isn't clicking though.  BTW, I have Wicket in
> action and it is fantastic, perhaps there is still something elduing me
> though...  I still can't wrap my head around why that property model doesn't
> update in the first case you show me.  If the property model is calling that
> object, and doing a get description each time it's called it's own
> getObject() method, why doesn't changing the reference externally work?
>
> If you simply point me to a page number and tell me to read until I
> understand, I would be greatful!
>
> Thanks again!
> Justin
>
>
> Martijn Dashorst wrote:
>>
>> No defensive copying happening. Just your plain old references
>> updating. Read the models page on the wiki about chaining models.
>>
>> Put this in a unit test case:
>>
>> State s = new State();
>> s.setDescription("I haven't read Wicket in Action but hear it helps
>> solve these questions");
>> PropertyModel pm = new PropertyModel(s, "description");
>> assertEquals("I haven't read Wicket in Action but hear it helps solve
>> these questions", pm.getObject());
>>
>> s = new State();
>> s.setDescription("I'll buy Wicket in Action, just because I now get
>> why my property model doesn't know this new state yet.");
>> assertEquals("I'll buy Wicket in Action, just because I now get why my
>> property model doesn't know this new state yet.", pm.getObject());
>>
>> This is basically what you are doing in your panel.
>>
>> but if you did:
>> State s = new State("Foo");
>> Model m = new Model();
>> m.setObject(s);
>> PropertyModel pm = new PropertyModel(m, "description");
>> assertEquals("Foo", pm.getObject());
>>
>> and now for the coup de grace:
>>
>> s = new State("Bar");
>> m.setObject(s);
>> assertEquals("Bar", pm.getObject());
>>
>> Martijn
>>
>> On Fri, Oct 24, 2008 at 3:57 PM, walnutmon <ju...@gmail.com>
>> wrote:
>>>
>>> I have two panels, a view panel where you can look for news and an edit
>>> panel.  The edit panel has a reference to a "news" object and all of it's
>>> form elements have property models that use that object.
>>>
>>> When I pass a news object into the panel on creation all of the form
>>> elements fill as expected.  However, if I set that object through a
>>> setter
>>> in the panel class, the elements do not update.  My theory (which may be
>>> wrong) is that the property model makes a defensive copy and therefore is
>>> not linked to the object in the class.  If this is true, can I resend the
>>> object to the property model?
>>>
>>> If that's not true, any insight as to what I may be doing wrong?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20150693.html
>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Become a Wicket expert, learn from the best: http://wicketinaction.com
>> Apache Wicket 1.3.4 is released
>> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20216529.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Forcing property models to update

Posted by walnutmon <ju...@gmail.com>.
I did as you said, and have the unit tests, and read the wiki on chaining
models... something still isn't clicking though.  BTW, I have Wicket in
action and it is fantastic, perhaps there is still something elduing me
though...  I still can't wrap my head around why that property model doesn't
update in the first case you show me.  If the property model is calling that
object, and doing a get description each time it's called it's own
getObject() method, why doesn't changing the reference externally work?

If you simply point me to a page number and tell me to read until I
understand, I would be greatful!

Thanks again!
Justin


Martijn Dashorst wrote:
> 
> No defensive copying happening. Just your plain old references
> updating. Read the models page on the wiki about chaining models.
> 
> Put this in a unit test case:
> 
> State s = new State();
> s.setDescription("I haven't read Wicket in Action but hear it helps
> solve these questions");
> PropertyModel pm = new PropertyModel(s, "description");
> assertEquals("I haven't read Wicket in Action but hear it helps solve
> these questions", pm.getObject());
> 
> s = new State();
> s.setDescription("I'll buy Wicket in Action, just because I now get
> why my property model doesn't know this new state yet.");
> assertEquals("I'll buy Wicket in Action, just because I now get why my
> property model doesn't know this new state yet.", pm.getObject());
> 
> This is basically what you are doing in your panel.
> 
> but if you did:
> State s = new State("Foo");
> Model m = new Model();
> m.setObject(s);
> PropertyModel pm = new PropertyModel(m, "description");
> assertEquals("Foo", pm.getObject());
> 
> and now for the coup de grace:
> 
> s = new State("Bar");
> m.setObject(s);
> assertEquals("Bar", pm.getObject());
> 
> Martijn
> 
> On Fri, Oct 24, 2008 at 3:57 PM, walnutmon <ju...@gmail.com>
> wrote:
>>
>> I have two panels, a view panel where you can look for news and an edit
>> panel.  The edit panel has a reference to a "news" object and all of it's
>> form elements have property models that use that object.
>>
>> When I pass a news object into the panel on creation all of the form
>> elements fill as expected.  However, if I set that object through a
>> setter
>> in the panel class, the elements do not update.  My theory (which may be
>> wrong) is that the property model makes a defensive copy and therefore is
>> not linked to the object in the class.  If this is true, can I resend the
>> object to the property model?
>>
>> If that's not true, any insight as to what I may be doing wrong?
>> --
>> View this message in context:
>> http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20150693.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> 
> 
> -- 
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.3.4 is released
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20216529.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Forcing property models to update

Posted by Igor Vaynberg <ig...@gmail.com>.
mmmmmmmmm popcorn!

-igor

On Fri, Oct 24, 2008 at 7:47 AM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
> Martijn is the guy that sprays buttered popcorn smell in the theatre vents
> for that extra little bit of subliminal selling power.  :)
>
> Seriously, though - buy the book - it's worth it's weight in gold.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
>
>
> On Fri, Oct 24, 2008 at 9:18 AM, Martijn Dashorst <
> martijn.dashorst@gmail.com> wrote:
>
>> No defensive copying happening. Just your plain old references
>> updating. Read the models page on the wiki about chaining models.
>>
>> Put this in a unit test case:
>>
>> State s = new State();
>> s.setDescription("I haven't read Wicket in Action but hear it helps
>> solve these questions");
>> PropertyModel pm = new PropertyModel(s, "description");
>> assertEquals("I haven't read Wicket in Action but hear it helps solve
>> these questions", pm.getObject());
>>
>> s = new State();
>> s.setDescription("I'll buy Wicket in Action, just because I now get
>> why my property model doesn't know this new state yet.");
>> assertEquals("I'll buy Wicket in Action, just because I now get why my
>> property model doesn't know this new state yet.", pm.getObject());
>>
>> This is basically what you are doing in your panel.
>>
>> but if you did:
>> State s = new State("Foo");
>> Model m = new Model();
>> m.setObject(s);
>> PropertyModel pm = new PropertyModel(m, "description");
>> assertEquals("Foo", pm.getObject());
>>
>> and now for the coup de grace:
>>
>> s = new State("Bar");
>> m.setObject(s);
>> assertEquals("Bar", pm.getObject());
>>
>> Martijn
>>
>> On Fri, Oct 24, 2008 at 3:57 PM, walnutmon <ju...@gmail.com>
>> wrote:
>> >
>>  > I have two panels, a view panel where you can look for news and an edit
>> > panel.  The edit panel has a reference to a "news" object and all of it's
>> > form elements have property models that use that object.
>> >
>> > When I pass a news object into the panel on creation all of the form
>> > elements fill as expected.  However, if I set that object through a
>> setter
>> > in the panel class, the elements do not update.  My theory (which may be
>> > wrong) is that the property model makes a defensive copy and therefore is
>> > not linked to the object in the class.  If this is true, can I resend the
>> > object to the property model?
>> >
>> > If that's not true, any insight as to what I may be doing wrong?
>> > --
>> > View this message in context:
>> http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20150693.html
>> > Sent from the Wicket - User mailing list archive at Nabble.com.
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>>
>>
>>
>> --
>> Become a Wicket expert, learn from the best: http://wicketinaction.com
>> Apache Wicket 1.3.4 is released
>> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Forcing property models to update

Posted by Jeremy Thomerson <je...@wickettraining.com>.
Martijn is the guy that sprays buttered popcorn smell in the theatre vents
for that extra little bit of subliminal selling power.  :)

Seriously, though - buy the book - it's worth it's weight in gold.

-- 
Jeremy Thomerson
http://www.wickettraining.com




On Fri, Oct 24, 2008 at 9:18 AM, Martijn Dashorst <
martijn.dashorst@gmail.com> wrote:

> No defensive copying happening. Just your plain old references
> updating. Read the models page on the wiki about chaining models.
>
> Put this in a unit test case:
>
> State s = new State();
> s.setDescription("I haven't read Wicket in Action but hear it helps
> solve these questions");
> PropertyModel pm = new PropertyModel(s, "description");
> assertEquals("I haven't read Wicket in Action but hear it helps solve
> these questions", pm.getObject());
>
> s = new State();
> s.setDescription("I'll buy Wicket in Action, just because I now get
> why my property model doesn't know this new state yet.");
> assertEquals("I'll buy Wicket in Action, just because I now get why my
> property model doesn't know this new state yet.", pm.getObject());
>
> This is basically what you are doing in your panel.
>
> but if you did:
> State s = new State("Foo");
> Model m = new Model();
> m.setObject(s);
> PropertyModel pm = new PropertyModel(m, "description");
> assertEquals("Foo", pm.getObject());
>
> and now for the coup de grace:
>
> s = new State("Bar");
> m.setObject(s);
> assertEquals("Bar", pm.getObject());
>
> Martijn
>
> On Fri, Oct 24, 2008 at 3:57 PM, walnutmon <ju...@gmail.com>
> wrote:
> >
>  > I have two panels, a view panel where you can look for news and an edit
> > panel.  The edit panel has a reference to a "news" object and all of it's
> > form elements have property models that use that object.
> >
> > When I pass a news object into the panel on creation all of the form
> > elements fill as expected.  However, if I set that object through a
> setter
> > in the panel class, the elements do not update.  My theory (which may be
> > wrong) is that the property model makes a defensive copy and therefore is
> > not linked to the object in the class.  If this is true, can I resend the
> > object to the property model?
> >
> > If that's not true, any insight as to what I may be doing wrong?
> > --
> > View this message in context:
> http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20150693.html
> > Sent from the Wicket - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.3.4 is released
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Forcing property models to update

Posted by Martijn Dashorst <ma...@gmail.com>.
No defensive copying happening. Just your plain old references
updating. Read the models page on the wiki about chaining models.

Put this in a unit test case:

State s = new State();
s.setDescription("I haven't read Wicket in Action but hear it helps
solve these questions");
PropertyModel pm = new PropertyModel(s, "description");
assertEquals("I haven't read Wicket in Action but hear it helps solve
these questions", pm.getObject());

s = new State();
s.setDescription("I'll buy Wicket in Action, just because I now get
why my property model doesn't know this new state yet.");
assertEquals("I'll buy Wicket in Action, just because I now get why my
property model doesn't know this new state yet.", pm.getObject());

This is basically what you are doing in your panel.

but if you did:
State s = new State("Foo");
Model m = new Model();
m.setObject(s);
PropertyModel pm = new PropertyModel(m, "description");
assertEquals("Foo", pm.getObject());

and now for the coup de grace:

s = new State("Bar");
m.setObject(s);
assertEquals("Bar", pm.getObject());

Martijn

On Fri, Oct 24, 2008 at 3:57 PM, walnutmon <ju...@gmail.com> wrote:
>
> I have two panels, a view panel where you can look for news and an edit
> panel.  The edit panel has a reference to a "news" object and all of it's
> form elements have property models that use that object.
>
> When I pass a news object into the panel on creation all of the form
> elements fill as expected.  However, if I set that object through a setter
> in the panel class, the elements do not update.  My theory (which may be
> wrong) is that the property model makes a defensive copy and therefore is
> not linked to the object in the class.  If this is true, can I resend the
> object to the property model?
>
> If that's not true, any insight as to what I may be doing wrong?
> --
> View this message in context: http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20150693.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Forcing property models to update

Posted by walnutmon <ju...@gmail.com>.
Thanks! That's exactly what I was looking for :jumping:


Jeremy Thomerson-5 wrote:
> 
> Do you mean you're doing this?
>  public class ViewPanel extends Panel {
>     private Object foo;
>     public ViewPanel(String id) {
>         super(id);
>         add(new EditPanel("edit", new PropertyModel(foo, "property")));
>         setFoo(new Foo());
>     }
> 
> }
> If so, you can fix it by replacing the property model with: new
> PropertyModel(this, "foo.property") - that way it will always pull the
> latest from from your ViewPanel.  Otherwise, you passed in a reference to
> an
> object, and then replaced your local reference with a reference to a new
> object - but that wouldn't replace references anywhere else.
> 
> -- 
> Jeremy Thomerson
> http://www.wickettraining.com
> 
> 
> On Fri, Oct 24, 2008 at 8:57 AM, walnutmon
> <ju...@gmail.com>wrote:
> 
>>
>> I have two panels, a view panel where you can look for news and an edit
>> panel.  The edit panel has a reference to a "news" object and all of it's
>> form elements have property models that use that object.
>>
>> When I pass a news object into the panel on creation all of the form
>> elements fill as expected.  However, if I set that object through a
>> setter
>> in the panel class, the elements do not update.  My theory (which may be
>> wrong) is that the property model makes a defensive copy and therefore is
>> not linked to the object in the class.  If this is true, can I resend the
>> object to the property model?
>>
>> If that's not true, any insight as to what I may be doing wrong?
>> --
>> View this message in context:
>> http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20150693.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20165705.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Forcing property models to update

Posted by Jeremy Thomerson <je...@wickettraining.com>.
Do you mean you're doing this?
 public class ViewPanel extends Panel {
    private Object foo;
    public ViewPanel(String id) {
        super(id);
        add(new EditPanel("edit", new PropertyModel(foo, "property")));
        setFoo(new Foo());
    }

}
If so, you can fix it by replacing the property model with: new
PropertyModel(this, "foo.property") - that way it will always pull the
latest from from your ViewPanel.  Otherwise, you passed in a reference to an
object, and then replaced your local reference with a reference to a new
object - but that wouldn't replace references anywhere else.

-- 
Jeremy Thomerson
http://www.wickettraining.com


On Fri, Oct 24, 2008 at 8:57 AM, walnutmon <ju...@gmail.com>wrote:

>
> I have two panels, a view panel where you can look for news and an edit
> panel.  The edit panel has a reference to a "news" object and all of it's
> form elements have property models that use that object.
>
> When I pass a news object into the panel on creation all of the form
> elements fill as expected.  However, if I set that object through a setter
> in the panel class, the elements do not update.  My theory (which may be
> wrong) is that the property model makes a defensive copy and therefore is
> not linked to the object in the class.  If this is true, can I resend the
> object to the property model?
>
> If that's not true, any insight as to what I may be doing wrong?
> --
> View this message in context:
> http://www.nabble.com/Forcing-property-models-to-update-tp20150693p20150693.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>