Tuesday, 15 May 2012

Wicket : Change an AjaxSelfUpdatingTimerBehavior

NextReports Server supports an automatic refresh for widgets. Just clicking "Edit Settings" for one widget will bring the following dialog:


Here user can modify "Refresh Time" which tells how many seconds should pass till next auto refresh.

To make this happen , an AjaxSelfUpdatingTimerBehavior is used. By default there is no refresh time set (value is 0). A change will imply to stop previous  AjaxSelfUpdatingTimerBehavior and to create a new one if that's the case:
for (Behavior behavior : widgetPanel.getBehaviors()) {
   if (behavior instanceof AjaxSelfUpdatingTimerBehavior) {
       ((AjaxSelfUpdatingTimerBehavior) behavior).stop();                   
   }
}          
if (refreshTime > 0) {
   widgetPanel.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(refreshTime)));
There are two things to have in mind:
  1. AjaxSelfUpdatingTimerBehavior must not be removed because, after stop, the event is called one more time on the client, so it has to be present.
  2. When we already have a refresh time set (greater than 0) and we want to modify its value, if a refresh is done when the dialog is opened, the desired panel no longer exists. So the user will be informed about this through a message (otherwise an error would have been raised):



1 comment:

  1. IEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.

    IEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.

    corporate training in chennai corporate training in chennai

    corporate training companies in india corporate training companies in india

    corporate training companies in chennai corporate training companies in chennai

    I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai

    ReplyDelete