java - Wicket's AjaxSelfUpdatingTimerBehavior stops updating after leaving and re-entering the page -


i have behavior added component(markupcontainer)

    ajaxselfupdatingtimerbehavior updatebehavior = new ajaxselfupdatingtimerbehavior(duration.seconds(3))     {           @override         public void onevent(component component, ievent<?> event) {             // business logic         }      }; 

somewhere , on same page have ajaxlink redirects page(in whom constructor pass actual page parameter) , on page have "back" ajaxlink redirects me , calling setresponsepage(myfirstpage) .

the problem though , when rendering page behavior updates once , stops updating once @ 3 seconds , constructed for.no problem faced behavior until leaving page.

probably not best solution , managed fix removing behavior onbeforerender() of page , adding again . declared field on page private int autoupdatebehaviorid = -1;

public void addupdatebehavior(component c) {     if(autoupdatebehaviorid >= 0)         c.remove(c.getbehaviorbyid(autoupdatebehaviorid));       ajaxselfupdatingtimerbehavior updatebehavior = new ajaxselfupdatingtimerbehavior(duration.seconds(3))     {          @override         public void onevent(component component, ievent<?> event) {             // bussines logic         }     };     c.add(updatebehavior);     autoupdatebehaviorid = c.getbehaviorid(updatebehavior); }   @override protected void onbeforerender() {     super.onbeforerender();     addupdatebehavior(mycontainer); } 

Comments