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.
java ajax wicket
jjerms
source share