【问题标题】:Wicket - Progress/Multiple Label UpdatesWicket - 进度/多个标签更新
【发布时间】:2012-07-18 20:02:01
【问题描述】:

我不确定这是否可能。当您单击“提交”按钮时,似乎有一种方法可以做到这一点。

private Button getButton(String id) 
{
    return new AjaxButton(id)
    {
            private static final long serialVersionUID = 1L;
            {
                setEnabled(true);
            }

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) 
            {
                debug = "Beginning a process....";
                target.addComponent(debugLabel);

                //Perform the first process

                debug = "Beginning second process....";
                target.addComponent(debugLabel);

                //Perform the second process

                debug = "Finishing....";
                target.addComponent(debugLabel);

                //Perform the third process

                debug = "Done.";
                target.addComponent(debugLabel);
            }
            @Override
            protected void onError(AjaxRequestTarget target, Form form)
            {
                //NO-OP
            }
        };
    }
}

如果不可能,是否可以替代多个实时更新?我想要它,所以底部有一个状态标签,它会更新并告诉您在该方法中完成了多少进度。

【问题讨论】:

    标签: java ajax label wicket target


    【解决方案1】:

    您必须在另一个线程中启动您希望收到通知的进程。然后,您可以使用绑定到标签的一些 ajax 行为定期检查状态信息来更新用户会话。

    在检票口 6 中,您还可以使用 WebSocketBehavior

    【讨论】:

    • 对不起,你把我弄丢了。能否提供一个简短的代码示例?
    • 我在家时(几小时后)会为您提供一份。您使用哪个检票口版本?
    • 不确定那个。我在 Eclipse 中引用了一个 wicket-1.4.17.jar 作为我的库之一。
    【解决方案2】:

    只需使用 AjaxTimerBehavior,它会每 1-2 秒更新一次您的标签。

    代码:

    add(new AbstractAjaxTimerBehavior(Duration.seconds(1))
            {
                @Override
                protected void onTimer(AjaxRequestTarget target)
                {
                    target.add(label);
                }
            });
    

    显然,该解决方案使用哑 AJAX 轮询,因此仅建议在 Intranet 或其他低流量站点上使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多