我有一个标签,每隔5秒检查一次新通知,并使用AjaxSelfUpdatingTimeBehaviour更新其文本以表示当前通知计数。 一切都很好,直到我打开另一个浏览器选项卡与同一页面,然后在两个选项卡上而不是更新标签,AjaxSelfUpdatingTimeBehaviour每5秒开始刷新页面。
private void initializeNotificationPanel() {
EventNotificationService notificationService = EventNotificationService
.getInstanceOfNotificationService();
List<Event> list = notificationService
.getSubscribedEvents(MyFoodSession.get().getUser());
final User currentUser = MyFoodSession.get().getUser();
final Label countLabel;
final WebMarkupContainer wmc = new WebMarkupContainer("markupContainer");
wmc.setOutputMarkupId(true);
final ListView<Event> listView = initListView(list);
wmc.add(listView);
listView.setVisible(false);
listView.setOutputMarkupId(true);
final AjaxLink<String> notificationLink = initializeAjaxLink(wmc,
listView);
if (notificationService.hasNotifications(currentUser)) {
countLabel = new Label("countlbl", list.size());
} else {
countLabel = new Label("countlbl", "0");
}
countLabel.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(5)) {
private static final long serialVersionUID = 1L;
EventNotificationService notificationService = EventNotificationService
.getInstanceOfNotificationService();
@Override
protected final void onPostProcessTarget(AjaxRequestTarget target) {
if (notificationService.hasNotifications(currentUser)) {
countLabel.setDefaultModelObject(""
+ notificationService.getSubscribedEvents(
MyFoodSession.get().getUser()).size());
} else {
countLabel.setDefaultModelObject("0");
}
}
});
wmc.add(notificationLink);
notificationLink.add(countLabel);
add(wmc);
}
答案 0 :(得分:0)
我想不出AjaxSelfUpdatingTimerBehavior应该暴露这种行为的原因。您应该创建一个快速入门并将其附加到新的Jira问题。