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:- AjaxSelfUpdatingTimerBehavior must not be removed because, after stop, the event is called one more time on the client, so it has to be present.
- 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):


No comments:
Post a Comment