You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Uwe Schäfer <sc...@thomas-daily.de> on 2009/05/06 20:25:19 UTC

Detaching models

hi

we have a problem here, which we think might be a common one, so i´d 
like to discuss.

from time to time we create models (mostly LDMs) that are not actually 
reachable by components. (yes, you can argue that this is stupid, but it 
happens where 1:1 mapping between component and model is not easy to apply)

the problem arising from there is of course that wicket does not know 
about this IModel and so wont detach() it.

yes, we could use Component.detach() as a hook to detach that LDM as 
well, but i tend to forget that.

if there were a central place to register IDetachables, life would be 
simpler. from what i´ve seen, detach is not guaranteed to be called only 
once, so we could do:

MyAbstractReadOnlyModel(){
  MyRequestCycle.get().registerForDetachment(this);}

and to

MyRequestCycle.detach(){
  super.detach();
  for(IDetachable d : this.setOfRegisteredIDetachables){
   d.detach();
  }
  this.registeredIDetachables.clear();
  ...

as well as

MyRequestCycle.registerForDetachment(IDetachable d);

wouldn´t it make sense to have something like this in the framework?
one drawback is that direct implementations of IModel could not be 
covered, but still it would be more convenient to just register them 
somewhere instead of overwriting the detach methods of their containers 
if we want them detached.

any thoughts, apart from the ones that claim this not to be a valid use 
of IModel? :)

cu uwe

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

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




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


Re: Detaching models

Posted by Uwe Schäfer <us...@thomas-daily.de>.
Igor Vaynberg schrieb:
> i thought not reachable means they are not in any default model slot...dunno

yep, that´s what i meant. sorry i wasn´t clear on that one.

using the listener to test the fields for IDetachable works pretty well. 
thanks again.


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


Re: Detaching models

Posted by Igor Vaynberg <ig...@gmail.com>.
i thought not reachable means they are not in any default model slot...dunno

-igor

On Wed, May 6, 2009 at 1:17 PM, Johan Compagner <jc...@gmail.com> wrote:
> Doesnt he say that the models arew really not reachable by the
> components? So how would that field scanning then work? If it are
> fields on components the currently the thing to do is simpel just make
> sure that those fields are detached in the detach method of the
> component that has those fields
>
> On 06/05/2009, Jeremy Thomerson <je...@wickettraining.com> wrote:
>> In 1.5 Igor is planning on doing this.  He's planning on making it
>> such that any IModel that your component holds as a field is
>> auto-detached.
>>
>> --
>> Jeremy Thomerson
>> http://www.wickettraining.com
>>
>>
>>
>>
>> 2009/5/6 Uwe Schäfer <sc...@thomas-daily.de>:
>>> hi
>>>
>>> we have a problem here, which we think might be a common one, so i´d like
>>> to
>>> discuss.
>>>
>>> from time to time we create models (mostly LDMs) that are not actually
>>> reachable by components. (yes, you can argue that this is stupid, but it
>>> happens where 1:1 mapping between component and model is not easy to
>>> apply)
>>>
>>> the problem arising from there is of course that wicket does not know
>>> about
>>> this IModel and so wont detach() it.
>>>
>>> yes, we could use Component.detach() as a hook to detach that LDM as well,
>>> but i tend to forget that.
>>>
>>> if there were a central place to register IDetachables, life would be
>>> simpler. from what i´ve seen, detach is not guaranteed to be called only
>>> once, so we could do:
>>>
>>> MyAbstractReadOnlyModel(){
>>>  MyRequestCycle.get().registerForDetachment(this);}
>>>
>>> and to
>>>
>>> MyRequestCycle.detach(){
>>>  super.detach();
>>>  for(IDetachable d : this.setOfRegisteredIDetachables){
>>>  d.detach();
>>>  }
>>>  this.registeredIDetachables.clear();
>>>  ...
>>>
>>> as well as
>>>
>>> MyRequestCycle.registerForDetachment(IDetachable d);
>>>
>>> wouldn´t it make sense to have something like this in the framework?
>>> one drawback is that direct implementations of IModel could not be
>>> covered,
>>> but still it would be more convenient to just register them somewhere
>>> instead of overwriting the detach methods of their containers if we want
>>> them detached.
>>>
>>> any thoughts, apart from the ones that claim this not to be a valid use of
>>> IModel? :)
>>>
>>> cu uwe
>>>
>>> --
>>> THOMAS DAILY GmbH
>>> Adlerstraße 19
>>> 79098 Freiburg
>>> Deutschland
>>> T  + 49 761 3 85 59 410
>>> F  + 49 761 3 85 59 550
>>> E  larbig@thomas-daily.de
>>> www.thomas-daily.de
>>>
>>> Geschäftsführer/Managing Directors:
>>> Wendy Thomas, Susanne Larbig
>>> Handelsregister Freiburg i.Br., HRB 3947
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>
> ---------------------------------------------------------------------
> 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: Detaching models

Posted by Igor Vaynberg <ig...@gmail.com>.
the standard way to handle this is to override component's ondetach()
and call detach() on the models directly.

-igor

2009/5/6 Uwe Schäfer <us...@thomas-daily.de>:
> Johan Compagner schrieb:
>>
>> If it are
>> fields on components the currently the thing to do is simpel just make
>> sure that those fields are detached in the detach method of the
>> component that has those fields
>
> sure, but this is quite easy to forget (that´s what i´m good at), so doing
> it from the Listener looks much safer to me :)
>
> thanks, uwe
>
> ---------------------------------------------------------------------
> 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: Detaching models

Posted by Johan Compagner <jc...@gmail.com>.
And for detecting if you did detach everything you could use a
serializable checker and/or specific object checker that will test
your complete page after it is detached. (or should be detached)

On 07/05/2009, Uwe Schäfer <us...@thomas-daily.de> wrote:
> Johan Compagner schrieb:
>> If it are
>> fields on components the currently the thing to do is simpel just make
>> sure that those fields are detached in the detach method of the
>> component that has those fields
>
> sure, but this is quite easy to forget (that´s what i´m good at), so
> doing it from the Listener looks much safer to me :)
>
> thanks, uwe
>
> ---------------------------------------------------------------------
> 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: Detaching models

Posted by Uwe Schäfer <us...@thomas-daily.de>.
Johan Compagner schrieb:
> If it are
> fields on components the currently the thing to do is simpel just make
> sure that those fields are detached in the detach method of the
> component that has those fields

sure, but this is quite easy to forget (that´s what i´m good at), so 
doing it from the Listener looks much safer to me :)

thanks, uwe

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


Re: Detaching models

Posted by Johan Compagner <jc...@gmail.com>.
Doesnt he say that the models arew really not reachable by the
components? So how would that field scanning then work? If it are
fields on components the currently the thing to do is simpel just make
sure that those fields are detached in the detach method of the
component that has those fields

On 06/05/2009, Jeremy Thomerson <je...@wickettraining.com> wrote:
> In 1.5 Igor is planning on doing this.  He's planning on making it
> such that any IModel that your component holds as a field is
> auto-detached.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
>
>
> 2009/5/6 Uwe Schäfer <sc...@thomas-daily.de>:
>> hi
>>
>> we have a problem here, which we think might be a common one, so i´d like
>> to
>> discuss.
>>
>> from time to time we create models (mostly LDMs) that are not actually
>> reachable by components. (yes, you can argue that this is stupid, but it
>> happens where 1:1 mapping between component and model is not easy to
>> apply)
>>
>> the problem arising from there is of course that wicket does not know
>> about
>> this IModel and so wont detach() it.
>>
>> yes, we could use Component.detach() as a hook to detach that LDM as well,
>> but i tend to forget that.
>>
>> if there were a central place to register IDetachables, life would be
>> simpler. from what i´ve seen, detach is not guaranteed to be called only
>> once, so we could do:
>>
>> MyAbstractReadOnlyModel(){
>>  MyRequestCycle.get().registerForDetachment(this);}
>>
>> and to
>>
>> MyRequestCycle.detach(){
>>  super.detach();
>>  for(IDetachable d : this.setOfRegisteredIDetachables){
>>  d.detach();
>>  }
>>  this.registeredIDetachables.clear();
>>  ...
>>
>> as well as
>>
>> MyRequestCycle.registerForDetachment(IDetachable d);
>>
>> wouldn´t it make sense to have something like this in the framework?
>> one drawback is that direct implementations of IModel could not be
>> covered,
>> but still it would be more convenient to just register them somewhere
>> instead of overwriting the detach methods of their containers if we want
>> them detached.
>>
>> any thoughts, apart from the ones that claim this not to be a valid use of
>> IModel? :)
>>
>> cu uwe
>>
>> --
>> THOMAS DAILY GmbH
>> Adlerstraße 19
>> 79098 Freiburg
>> Deutschland
>> T  + 49 761 3 85 59 410
>> F  + 49 761 3 85 59 550
>> E  larbig@thomas-daily.de
>> www.thomas-daily.de
>>
>> Geschäftsführer/Managing Directors:
>> Wendy Thomas, Susanne Larbig
>> Handelsregister Freiburg i.Br., HRB 3947
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>

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


Re: Detaching models

Posted by Uwe Schäfer <us...@thomas-daily.de>.
James Carman schrieb:

> Refer to the injection code to find out how to do the scanning.
>> you can do this now, no need to wait for 1.5. simply create a
>> detachlistener that scans the class for imodel fields and detaches
>> them.

awesome. i was not aware of this one. thanks.

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


Re: Detaching models

Posted by James Carman <jc...@carmanconsulting.com>.
Refer to the injection code to find out how to do the scanning.

On Wed, May 6, 2009 at 2:47 PM, Igor Vaynberg <ig...@gmail.com> wrote:
> you can do this now, no need to wait for 1.5. simply create a
> detachlistener that scans the class for imodel fields and detaches
> them.
>
> -igor
>
> On Wed, May 6, 2009 at 11:38 AM, Jeremy Thomerson
> <je...@wickettraining.com> wrote:
>> In 1.5 Igor is planning on doing this.  He's planning on making it
>> such that any IModel that your component holds as a field is
>> auto-detached.
>>
>> --
>> Jeremy Thomerson
>> http://www.wickettraining.com
>>
>>
>>
>>
>> 2009/5/6 Uwe Schäfer <sc...@thomas-daily.de>:
>>> hi
>>>
>>> we have a problem here, which we think might be a common one, so i´d like to
>>> discuss.
>>>
>>> from time to time we create models (mostly LDMs) that are not actually
>>> reachable by components. (yes, you can argue that this is stupid, but it
>>> happens where 1:1 mapping between component and model is not easy to apply)
>>>
>>> the problem arising from there is of course that wicket does not know about
>>> this IModel and so wont detach() it.
>>>
>>> yes, we could use Component.detach() as a hook to detach that LDM as well,
>>> but i tend to forget that.
>>>
>>> if there were a central place to register IDetachables, life would be
>>> simpler. from what i´ve seen, detach is not guaranteed to be called only
>>> once, so we could do:
>>>
>>> MyAbstractReadOnlyModel(){
>>>  MyRequestCycle.get().registerForDetachment(this);}
>>>
>>> and to
>>>
>>> MyRequestCycle.detach(){
>>>  super.detach();
>>>  for(IDetachable d : this.setOfRegisteredIDetachables){
>>>  d.detach();
>>>  }
>>>  this.registeredIDetachables.clear();
>>>  ...
>>>
>>> as well as
>>>
>>> MyRequestCycle.registerForDetachment(IDetachable d);
>>>
>>> wouldn´t it make sense to have something like this in the framework?
>>> one drawback is that direct implementations of IModel could not be covered,
>>> but still it would be more convenient to just register them somewhere
>>> instead of overwriting the detach methods of their containers if we want
>>> them detached.
>>>
>>> any thoughts, apart from the ones that claim this not to be a valid use of
>>> IModel? :)
>>>
>>> cu uwe
>>>
>>> --
>>> THOMAS DAILY GmbH
>>> Adlerstraße 19
>>> 79098 Freiburg
>>> Deutschland
>>> T  + 49 761 3 85 59 410
>>> F  + 49 761 3 85 59 550
>>> E  larbig@thomas-daily.de
>>> www.thomas-daily.de
>>>
>>> Geschäftsführer/Managing Directors:
>>> Wendy Thomas, Susanne Larbig
>>> Handelsregister Freiburg i.Br., HRB 3947
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>
> ---------------------------------------------------------------------
> 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: Detaching models

Posted by Igor Vaynberg <ig...@gmail.com>.
you can do this now, no need to wait for 1.5. simply create a
detachlistener that scans the class for imodel fields and detaches
them.

-igor

On Wed, May 6, 2009 at 11:38 AM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
> In 1.5 Igor is planning on doing this.  He's planning on making it
> such that any IModel that your component holds as a field is
> auto-detached.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
>
>
> 2009/5/6 Uwe Schäfer <sc...@thomas-daily.de>:
>> hi
>>
>> we have a problem here, which we think might be a common one, so i´d like to
>> discuss.
>>
>> from time to time we create models (mostly LDMs) that are not actually
>> reachable by components. (yes, you can argue that this is stupid, but it
>> happens where 1:1 mapping between component and model is not easy to apply)
>>
>> the problem arising from there is of course that wicket does not know about
>> this IModel and so wont detach() it.
>>
>> yes, we could use Component.detach() as a hook to detach that LDM as well,
>> but i tend to forget that.
>>
>> if there were a central place to register IDetachables, life would be
>> simpler. from what i´ve seen, detach is not guaranteed to be called only
>> once, so we could do:
>>
>> MyAbstractReadOnlyModel(){
>>  MyRequestCycle.get().registerForDetachment(this);}
>>
>> and to
>>
>> MyRequestCycle.detach(){
>>  super.detach();
>>  for(IDetachable d : this.setOfRegisteredIDetachables){
>>  d.detach();
>>  }
>>  this.registeredIDetachables.clear();
>>  ...
>>
>> as well as
>>
>> MyRequestCycle.registerForDetachment(IDetachable d);
>>
>> wouldn´t it make sense to have something like this in the framework?
>> one drawback is that direct implementations of IModel could not be covered,
>> but still it would be more convenient to just register them somewhere
>> instead of overwriting the detach methods of their containers if we want
>> them detached.
>>
>> any thoughts, apart from the ones that claim this not to be a valid use of
>> IModel? :)
>>
>> cu uwe
>>
>> --
>> THOMAS DAILY GmbH
>> Adlerstraße 19
>> 79098 Freiburg
>> Deutschland
>> T  + 49 761 3 85 59 410
>> F  + 49 761 3 85 59 550
>> E  larbig@thomas-daily.de
>> www.thomas-daily.de
>>
>> Geschäftsführer/Managing Directors:
>> Wendy Thomas, Susanne Larbig
>> Handelsregister Freiburg i.Br., HRB 3947
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>

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


Re: Detaching models

Posted by Jeremy Thomerson <je...@wickettraining.com>.
In 1.5 Igor is planning on doing this.  He's planning on making it
such that any IModel that your component holds as a field is
auto-detached.

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




2009/5/6 Uwe Schäfer <sc...@thomas-daily.de>:
> hi
>
> we have a problem here, which we think might be a common one, so i´d like to
> discuss.
>
> from time to time we create models (mostly LDMs) that are not actually
> reachable by components. (yes, you can argue that this is stupid, but it
> happens where 1:1 mapping between component and model is not easy to apply)
>
> the problem arising from there is of course that wicket does not know about
> this IModel and so wont detach() it.
>
> yes, we could use Component.detach() as a hook to detach that LDM as well,
> but i tend to forget that.
>
> if there were a central place to register IDetachables, life would be
> simpler. from what i´ve seen, detach is not guaranteed to be called only
> once, so we could do:
>
> MyAbstractReadOnlyModel(){
>  MyRequestCycle.get().registerForDetachment(this);}
>
> and to
>
> MyRequestCycle.detach(){
>  super.detach();
>  for(IDetachable d : this.setOfRegisteredIDetachables){
>  d.detach();
>  }
>  this.registeredIDetachables.clear();
>  ...
>
> as well as
>
> MyRequestCycle.registerForDetachment(IDetachable d);
>
> wouldn´t it make sense to have something like this in the framework?
> one drawback is that direct implementations of IModel could not be covered,
> but still it would be more convenient to just register them somewhere
> instead of overwriting the detach methods of their containers if we want
> them detached.
>
> any thoughts, apart from the ones that claim this not to be a valid use of
> IModel? :)
>
> cu uwe
>
> --
> THOMAS DAILY GmbH
> Adlerstraße 19
> 79098 Freiburg
> Deutschland
> T  + 49 761 3 85 59 410
> F  + 49 761 3 85 59 550
> E  larbig@thomas-daily.de
> www.thomas-daily.de
>
> Geschäftsführer/Managing Directors:
> Wendy Thomas, Susanne Larbig
> Handelsregister Freiburg i.Br., HRB 3947
>
>
>
>
> ---------------------------------------------------------------------
> 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