You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Joseph Pachod <jp...@thomas-daily.de> on 2010/07/21 17:25:14 UTC

Why is Component.setDefaultModelObject() checking for equality before setting ?

hi

I was surprised to see, in Component.setDefaultModelObject(), the 
following code:
        // Check whether this will result in an actual change
        if (!getModelComparator().compare(this, object))
        {
            modelChanging();
            model.setObject(object);
            modelChanged();
        }

getModelComparator() being down to, by default, a simple equals between 
the present model object and the object to set.

This setDefaultModelObject is called from updateModel of FormComponent.

Why is that ?

AFAIK, it brings quite some disadvantages:
- adds quite some cost (equals test can be quite expensive, and are 
always more than just assigning a reference)
- if equals isn't properly implemented, can be either meaningless 
(default equals being different instances are never equals even if 
logically equal) or not appropriate (in entities, my equals is based on 
the id, which when editing obviously causes an issue here)
- IModel implementations don't behave like that (setObject for a 
PropertyModel or a Model don't check for non equality)

Yet I don't see any added value...

In the end, I see potential for misbehavior or unexpected one and no 
added value.

So, why it it this way ?

thanks in advance
++

-- 
Joseph Pachod
IT

THOMAS DAILY GmbH
Adlerstraße 19
79098 Freiburg
Deutschland
T  + 49 761 3 85 59 506
F  + 49 761 3 85 59 550
E  joseph.pachod@thomas-daily.de
www.thomas-daily.de

Geschäftsführer/Managing Directors:
Wendy Thomas, Susanne Larbig
Handelsregister Freiburg i.Br., HRB 3947

Registrieren Sie sich unter https://www.thomas-daily.de/user/sign-in für die TD Morning News, eine kostenlose Auswahl aktueller Themen aus TD Premium, morgens ab 9:15 in Ihrer Mailbox.

Aktuelle Presseinformationen für die TD Morning News und TD Premium nimmt unsere Redaktion unter redaktion@thomas-daily.de entgegen.
Redaktionsschluss für die TD Morning News ist täglich um 8:45.

Register free of charge at https://www.thomas-daily.de/user/sign-in to have the TD Morning News, a selection of the latest topics from TD Premium, delivered to your mailbox from 9:15 every morning.

Our editorial department receives the latest press releases for the TD Morning News and TD Premium at redaktion@thomas-daily.de. The editorial deadline for the TD Morning News is 8.45am daily. 


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


Re: Why is Component.setDefaultModelObject() checking for equality before setting ?

Posted by Joseph Pachod <jp...@thomas-daily.de>.
Igor Vaynberg wrote:
> the added value is that if wicket detects that the set is a noop
> because the objects are the same it doesnt need to create a new
> version of the page.
>   
ok, makes more sense :)

I was quite a surprised though, I had not heard of it at all even read 
all these wicket books and using wicket for quite some time. Yet making 
this corner stuff more visible is probably hard.

thanks for your answer anyway

++
joseph



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


Re: Why is Component.setDefaultModelObject() checking for equality before setting ?

Posted by Igor Vaynberg <ig...@gmail.com>.
the added value is that if wicket detects that the set is a noop
because the objects are the same it doesnt need to create a new
version of the page.

-igor

On Wed, Jul 21, 2010 at 8:25 AM, Joseph Pachod <jp...@thomas-daily.de> wrote:
> hi
>
> I was surprised to see, in Component.setDefaultModelObject(), the following
> code:
>       // Check whether this will result in an actual change
>       if (!getModelComparator().compare(this, object))
>       {
>           modelChanging();
>           model.setObject(object);
>           modelChanged();
>       }
>
> getModelComparator() being down to, by default, a simple equals between the
> present model object and the object to set.
>
> This setDefaultModelObject is called from updateModel of FormComponent.
>
> Why is that ?
>
> AFAIK, it brings quite some disadvantages:
> - adds quite some cost (equals test can be quite expensive, and are always
> more than just assigning a reference)
> - if equals isn't properly implemented, can be either meaningless (default
> equals being different instances are never equals even if logically equal)
> or not appropriate (in entities, my equals is based on the id, which when
> editing obviously causes an issue here)
> - IModel implementations don't behave like that (setObject for a
> PropertyModel or a Model don't check for non equality)
>
> Yet I don't see any added value...
>
> In the end, I see potential for misbehavior or unexpected one and no added
> value.
>
> So, why it it this way ?
>
> thanks in advance
> ++
>
> --
> Joseph Pachod
> IT
>
> THOMAS DAILY GmbH
> Adlerstraße 19
> 79098 Freiburg
> Deutschland
> T  + 49 761 3 85 59 506
> F  + 49 761 3 85 59 550
> E  joseph.pachod@thomas-daily.de
> www.thomas-daily.de
>
> Geschäftsführer/Managing Directors:
> Wendy Thomas, Susanne Larbig
> Handelsregister Freiburg i.Br., HRB 3947
>
> Registrieren Sie sich unter https://www.thomas-daily.de/user/sign-in für die
> TD Morning News, eine kostenlose Auswahl aktueller Themen aus TD Premium,
> morgens ab 9:15 in Ihrer Mailbox.
>
> Aktuelle Presseinformationen für die TD Morning News und TD Premium nimmt
> unsere Redaktion unter redaktion@thomas-daily.de entgegen.
> Redaktionsschluss für die TD Morning News ist täglich um 8:45.
>
> Register free of charge at https://www.thomas-daily.de/user/sign-in to have
> the TD Morning News, a selection of the latest topics from TD Premium,
> delivered to your mailbox from 9:15 every morning.
>
> Our editorial department receives the latest press releases for the TD
> Morning News and TD Premium at redaktion@thomas-daily.de. The editorial
> deadline for the TD Morning News is 8.45am daily.
>
> ---------------------------------------------------------------------
> 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