How can I properly remove AjaxSelfUpdatingTimerBehavior from a component in Apache Wicket?

I'm having trouble adding and then removing AjaxSelfUpdatingTimerBehavior in Apache Wicket. The behavior is added well, but then, as soon as I delete the behavior, I get the "Expired Page" message that appears in the browser very soon, I think because the removal was not clean. My setup is basically a shortcut that starts to change according to the timer and two links: "go" and "stop". I want to be able to click "go" and then "stop" (obviously, I know that it will never work the other way around!). Here is my full markup:

<html> <body> <span wicket:id="message">message will be here</span><br/> <a wicket:id="go">Go</a><br/> <a wicket:id="stop">Stop</a> </body> </html> 

and here is my code:

 // imports all from standard wicket public class HomePage extends WebPage { private static final int INTERVAL = 500; public HomePage(final PageParameters parameters) { final Component label = new Label("message", "Hello").setOutputMarkupId(true); add(label); final IBehavior updater = new AjaxSelfUpdatingTimerBehavior(Duration .milliseconds(INTERVAL)) { @Override protected void onPostProcessTarget(AjaxRequestTarget target) { label.setDefaultModelObject(String.valueOf(System.nanoTime())); } }; AjaxLink<String> go = new AjaxLink<String>("go") { @Override public void onClick(AjaxRequestTarget target) { label.add(updater); target.addComponent(label); } }; AjaxLink<String> stop = new AjaxLink<String>("stop") { @Override public void onClick(AjaxRequestTarget target) { label.remove(updater); target.addComponent(label); } }; add(go, stop); } } 

I am using Wicket 1.4.3.

Any help is greatly appreciated. Thanks.

+7
java ajax wicket
source share
2 answers

I solved this using the stop() method, and not trying to completely remove the behavior.

I really want to completely remove it at some point after it stops (because my solution includes a new behavior, every time I press "go" and I want to continue to stop and start without charging a million actions), so I got rounding it up, maintaining a list of deletions that need to be removed in a later round.

+3
source share

It would be nice to be able to call restart () or something in AbstractAjaxTimerBehavior to re-enable timer behavior.

0
source share

All Articles