I've attached a patch to WICKET-4959 that introduces
Behavior#onRemove(Component) - a callback that is called when a host
component is removed from its parent.

But there is still a chance for race , much lower than before but still
here .. :-/


On Thu, Jan 17, 2013 at 1:00 PM, Martin Grigorov <[email protected]>wrote:

>
>
>
> On Thu, Jan 17, 2013 at 12:36 PM, Sven Meier <[email protected]> wrote:
>
>> I've used component#detach() when the code didn't have a reference to the
>> model.
>
>
>  component.getModel().detach() ?! :-)
>
>
>>
>>
>> > Maybe we need another callback method in Behavior
>>
>> A #removed() callback might be useful ... or overkill ;)
>>
>> Sven
>>
>>
>> On 01/17/2013 11:33 AM, Martin Grigorov wrote:
>>
>>> On Thu, Jan 17, 2013 at 12:17 PM, Sven Meier <[email protected]> wrote:
>>>
>>>           @Override
>>>>
>>>>>          public void detach(Component component)
>>>>>          {
>>>>>                  AjaxRequestTarget target =
>>>>> component.getRequestCycle().**
>>>>>
>>>>> find(AjaxRequestTarget.class);
>>>>>                  if (target != null)
>>>>>                  {
>>>>>                          stop(target);
>>>>>                  }
>>>>>                  super.detach(component);
>>>>>          }
>>>>>
>>>>>
>>>> A small nitpick:
>>>> Removing a component in an ART might not be the only reason why
>>>> #detach()
>>>> is called. A developer might call component#detach() to force a LDM to
>>>> reload on the next render.
>>>>
>>>
>>> Very good point!
>>> I'm not sure this is so small. I'd use model.detach() but one could
>>> detach
>>> the component ...
>>> Maybe we need another callback method in Behavior
>>>
>>>
>>>
>>>> Sven
>>>>
>>>>
>>>> On 01/17/2013 10:20 AM, [email protected] wrote:
>>>>
>>>>  WICKET-4959 Unproperly detached Behavior with TabbedPanels
>>>>>
>>>>> Stop the Ajax timer behavior when the behavior's component is removed
>>>>> from the tree
>>>>>
>>>>>
>>>>> Project: 
>>>>> http://git-wip-us.apache.org/****repos/asf/wicket/repo<http://git-wip-us.apache.org/**repos/asf/wicket/repo>
>>>>> <http://**git-wip-us.apache.org/repos/**asf/wicket/repo<http://git-wip-us.apache.org/repos/asf/wicket/repo>
>>>>> >
>>>>> Commit: http://git-wip-us.apache.org/****repos/asf/wicket/commit/****
>>>>> 0b78d759<http://git-wip-us.apache.org/**repos/asf/wicket/commit/**0b78d759>
>>>>> <http://git-wip-us.**apache.org/repos/asf/wicket/**commit/0b78d759<http://git-wip-us.apache.org/repos/asf/wicket/commit/0b78d759>
>>>>> >
>>>>> Tree: http://git-wip-us.apache.org/****repos/asf/wicket/tree/**
>>>>> 0b78d759<http://git-wip-us.apache.org/**repos/asf/wicket/tree/0b78d759>
>>>>> <http://git-wip-us.**apache.org/repos/asf/wicket/**tree/0b78d759<http://git-wip-us.apache.org/repos/asf/wicket/tree/0b78d759>
>>>>> >
>>>>> Diff: http://git-wip-us.apache.org/****repos/asf/wicket/diff/**
>>>>> 0b78d759<http://git-wip-us.apache.org/**repos/asf/wicket/diff/0b78d759>
>>>>> <http://git-wip-us.**apache.org/repos/asf/wicket/**diff/0b78d759<http://git-wip-us.apache.org/repos/asf/wicket/diff/0b78d759>
>>>>> >
>>>>>
>>>>> Branch: refs/heads/master
>>>>> Commit: 0b78d759220c1b09abb0d47b500775****7bbfeb4e0c
>>>>>
>>>>> Parents: e37a9e1
>>>>> Author: Martin Tzvetanov Grigorov <[email protected]>
>>>>> Authored: Thu Jan 17 11:18:22 2013 +0200
>>>>> Committer: Martin Tzvetanov Grigorov <[email protected]>
>>>>> Committed: Thu Jan 17 11:18:22 2013 +0200
>>>>>
>>>>> ------------------------------****----------------------------**--**
>>>>> ----------
>>>>>    .../wicket/ajax/****AbstractAjaxTimerBehavior.java     |   11
>>>>> +++++++++++
>>>>>
>>>>>    1 files changed, 11 insertions(+), 0 deletions(-)
>>>>> ------------------------------****----------------------------**--**
>>>>> ----------
>>>>>
>>>>>
>>>>> http://git-wip-us.apache.org/****repos/asf/wicket/blob/**<http://git-wip-us.apache.org/**repos/asf/wicket/blob/**>
>>>>> 0b78d759/wicket-core/src/main/****java/org/apache/wicket/ajax/****
>>>>> AbstractAjaxTimerBehavior.**java<http://git-wip-us.apache.**
>>>>> org/repos/asf/wicket/blob/**0b78d759/wicket-core/src/main/**
>>>>> java/org/apache/wicket/ajax/**AbstractAjaxTimerBehavior.java<http://git-wip-us.apache.org/repos/asf/wicket/blob/0b78d759/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java>
>>>>> **>
>>>>> ------------------------------****----------------------------**--**
>>>>> ----------
>>>>> diff --git a/wicket-core/src/main/java/****org/apache/wicket/ajax/****
>>>>> AbstractAjaxTimerBehavior.java
>>>>> b/wicket-core/src/main/java/****org/apache/wicket/ajax/**
>>>>> AbstractAjaxTimerBehavior.java
>>>>> index 83edeaa..a80921d 100644
>>>>> --- a/wicket-core/src/main/java/****org/apache/wicket/ajax/**
>>>>> AbstractAjaxTimerBehavior.java
>>>>> +++ b/wicket-core/src/main/java/****org/apache/wicket/ajax/**
>>>>>
>>>>> AbstractAjaxTimerBehavior.java
>>>>> @@ -194,4 +194,15 @@ public abstract class AbstractAjaxTimerBehavior
>>>>> extends AbstractDefaultAjaxBehav
>>>>>                  String timeoutHandle = getTimeoutHandle();
>>>>>                  target.prependJavaScript("**
>>>>> clearTimeout("+timeoutHandle+"****); delete "+timeoutHandle+";");
>>>>>
>>>>>          }
>>>>> +
>>>>> +       @Override
>>>>> +       public void detach(Component component)
>>>>> +       {
>>>>> +               AjaxRequestTarget target =
>>>>> component.getRequestCycle().**
>>>>>
>>>>> find(AjaxRequestTarget.class);
>>>>> +               if (target != null)
>>>>> +               {
>>>>> +                       stop(target);
>>>>> +               }
>>>>> +               super.detach(component);
>>>>> +       }
>>>>>    }
>>>>>
>>>>>
>>>>>
>>>
>>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com <http://jweekend.com/>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Reply via email to