我有一个链接应该在服务器上激活一些进程并且不活动,然后它应该在后台监视这个进程,当它完成时,应该更新链接.所有这些操作都应该在AJAX的帮助下完成.
链接转换示例:- > - >Bake a cake Baking a cake Load baked cake
这个工作流程可以在onClick方法中完成AjaxLink,但它会阻止另一个AJAX请求,并且会在很长的处理时间内完成.
这里的一个选项是使用AbstractAjaxTimerBehavior定期轮询服务器状态并相应地更新标签
/* Create stopped timer */
AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.seconds(1)) {
@Override
protected void onTimer(AjaxRequestTarget target) {
if (serverIsReady()) {
/* Stop timer */
this.stop(target);
/* Update UI */
label.setDefaultModel("Load baked cake");
target.add(label);
}
}
});
link.add(timer);
timer.stop();
/* Create triggering event behaviour */
link.add(new AjaxEventBehavior("onclick") {
@Override
protected void onEvent(AjaxRequestTarget target) {
/* Update UI */
label.setDefaultModel("Baking a cake");
target.add(label);
/* Start timer */
timer.restart(target); /* It seems this method doesn't exist in Wicket 1.4 */
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
985 次 |
| 最近记录: |