With 1.5 Wicket sends notifications before removing and after adding an element. See test "Wicket.DOM.replace - test event notifications" at http://git-wip-us.apache.org/repos/asf/wicket/repo?p=wicket.git;a=blob_plain;f=wicket-core/src/test/js/dom.js;hb=master for an example. But you need to upgrade to 1.5 ...
On Thu, Mar 15, 2012 at 3:05 PM, Stijn de Witt <[email protected]> wrote: > We are still at Wicket 1.4 even... > > However, presumably there is a method one can implement to respond to the > removal of components as well as the adding? > > Upgrading to a snapshot is probably not allowed by my company policy and I'd > rather not modify Wicket itself... But surely others must have found a way to > remove events bound to components? Seems like fundamental stuff. > > -Stijn > > > -----Original Message----- > From: Martin Grigorov [mailto:[email protected]] > Sent: donderdag 15 maart 2012 13:59 > To: [email protected] > Subject: Re: How to cleanup when plugin/behavior is removed through Ajax? > > On Thu, Mar 15, 2012 at 2:51 PM, Stijn de Witt > <[email protected]> wrote: >> Hi Martin, thanks for your quick response! >> >>>> AFAIK jQuery unbinds all registered event listeners for a DOM element when >>>> this element is removed with jQuery method like #remove(), #replaceWith(), >>>> etc. >> >> I think so too... However I am not sure that that is indeed the way that >> Wicket removes components that are replaced by an Ajax request? I think >> Wicket relies on their own code that they based on Prototype JS ? > > No. Including version 1.5 Wicket uses its own JavaScript code to do this (see > wicket-ajax.js #replaceOuterHtml()). > In Wicket 6.0 jQuery is used behind the scenes and this method is implemented > with: jQuery(oldElement).after(newElementHtml".remove(). > > If upgrading to Wicket 6.0-SNAPSHOT is not an option for you then you can use > monkey patching approach to override the old impl in 1.5 > >> >>>> Better ask in jQuery forums. >> >> I am not sure if that is the right place. Seems to me that Wicket is doing >> the inserting / removing of the components for the page. The statement() >> method lets me hook into the insertion phase to add my own listeners (be it >> with jQuery or any other framework) so it seems to me there should also be a >> corresponding method for the removing phase where you can unhook/unbind >> events etc... >> >> -Stijn >> >> >> -----Original Message----- >> From: Martin Grigorov [mailto:[email protected]] >> Sent: donderdag 15 maart 2012 13:32 >> To: [email protected] >> Subject: Re: How to cleanup when plugin/behavior is removed through Ajax? >> >> Hi, >> >> AFAIK jQuery unbinds all registered event listeners for a DOM element when >> this element is removed with jQuery method like #remove(), #replaceWith(), >> etc. >> But I'm not sure this is the case when you remove a parent element of an >> element with event listeners. Better ask in jQuery forums. >> >> On Thu, Mar 15, 2012 at 11:22 AM, Stijn de Witt >> <[email protected]> wrote: >>> Hi. We are using WiQuery in our application to attach some behaviors to >>> some components. For example a resize behavior to react on the component >>> being resized. I added some debug logging and I see that when we switch >>> panels (through Ajax) all event listeners for the components on the new >>> panel are added, but the old ones from the panel being replaced are never >>> removed. So the list of event handlers just grows and grows... >>> >>> We register event listeners in the statement method of the WiQuery >>> behavior, like this: >>> >>> public abstract class BaResizeEventBehavior extends >>> WiQueryAbstractBehavior { >>> // ... >>> @Override public JsStatement statement() { >>> return new JsQuery(getComponent()).$().chain("resize", new >>> JsScope() { >>> @Override public void execute(JsScopeContext aScopeContext) { >>> // event listener implementation here >>> } >>> }); >>> } >>> } >>> >>> This will generate Javascript code that looks like this: >>> >>> $('#componentId').resize(function() { >>> // event listener implementation here }); >>> >>> This code will register a jQuery event on the component with id >>> 'componentId'. However when this component disappears from the page, I >>> would like this event handler to be unbound again, but that does not happen. >>> >>> Any ideas? >>> >>> Thanks, >>> >>> -Stijn >>> >>> P.S: >>> This is cross-posted to >>> http://groups.google.com/group/wiquery-plugins/browse_thread/thread/aaceac38d60adbcf >>> because that group seems to have hardly any traffic... Hopefully one of >>> the Wicket gurus here knows a bit about WiQuery as well? Although maybe >>> this question can be formulated for Wicket as well as also there when doing >>> Ajax we need to clean up after components when they are removed from the >>> page right? >> >> >> >> -- >> Martin Grigorov >> jWeekend >> Training, Consulting, Development >> http://jWeekend.com >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> > > > > -- > Martin Grigorov > jWeekend > Training, Consulting, Development > http://jWeekend.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
