actually all variables referenced in such manner become fields of the
anonymous class and are accessible via reflection.

-igor

On Fri, Apr 6, 2012 at 10:23 AM, Carl-Eric Menzel <cmen...@wicketbuch.de> wrote:
> At first glance I'm torn about this, to be honest. On the one hand,
> yes, not having to do that would be neat. On the other hand, that makes
> models even more magic to new users, and not obvious what happens.
> Especially if you create a model in e.g. your constructor and just
> reference it a method of an anonymous class, that would not be detected
> by this.
>
> MyComponent() {
>   IModel foo = createSomeModel();
>   add(new Link() { onClick() {
>      // use foo model
>   }});
> }
>
> This model would not be detected by reflection, as far as I can tell.
> So some models would be magically detached, others wouldn't. That might
> lead to more confusion than just telling people "Well just detach it!".
>
> So far we've been getting along with a simple rule: "Detach the model
> yourself or pass it on to someone else." Easy to remember and works
> reliably. This is what I've been teaching too.
>
> I guess I'd have to see it in practice to make up my mind really. Is it
> possible to offer it as an extension or something in wicketstuff, at
> least for now?
>
> Carl-Eric
> www.wicketbuch.de
>
> On Fri, 6 Apr 2012 09:42:42 -0700
> Igor Vaynberg <igor.vaynb...@gmail.com> wrote:
>
>> i wrote a IDetachListener that automatically detaches any IModel
>> fields found on components. is this something we would be interested
>> in for core? its been running in production for a while without any
>> noticeable overhead and its nice not to have to implemenet onDetach()
>> all the time just to forward it to secondary models. the only downside
>> is that once we introduce this feature we can never remote it because
>> doing so will break code.
>>
>> thoughts?
>>
>> -igor
>

Reply via email to