一種選擇是使用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 */
}
});
看看這個問題[檢票如何處理長時間運行的tesks(http://stackoverflow.com /問題/ 2310421 /檢票如何到把手長時間運行的任務) – Glenner003