0

我有一个标签,它每 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);

}
4

1 回答 1

0

我想不出为什么 AjaxSelfUpdatingTimerBehavior 应该公开这种行为的原因。您应该创建一个快速入门并将其附加到新的 Jira 问题中。

于 2013-08-23T13:05:16.310 回答