Wicket 6.3.0 AjaxLink:IAjaxCallListener行为

时间:2012-12-13 16:14:17

标签: ajax wicket

在Wicket 6之前,IAjaxCallDecorator.decorateScipt返回的javascript代码在点击后立即执行。我根据migration-guide迁移了IAjaxCallDecorator。 通过在5秒内单击3次链接,预期结果为:

  • getPrecondition
  • getPrecondition
  • getPrecondition
  • getSuccessHandler
  • getSuccessHandler
  • getSuccessHandler

但结果是:

  • getPrecondition
  • getSuccessHandler
  • getPrecondition
  • getSuccessHandler
  • getPrecondition
  • getSuccessHandler

使用案例:阻止直到Ajax请求完成,请参阅http://my.safaribooksonline.com/book/-/9781849511605/deeper-into-ajax/ch07lvl1sec04(页172)

有没有其他方法可以将IAjaxCallDecorator迁移到Wicket 6?

public class HomePage extends WebPage {

 public HomePage(final PageParameters parameters) {
  add(new Label("version", getApplication().getFrameworkSettings().getVersion()));

  AjaxLink<Void> blockingLink = new AjaxLink<Void>("blockingLink") {
    @Override
    public void onClick(AjaxRequestTarget target) {
      try {
        Thread.sleep(5000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
    @Override
    protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
      super.updateAjaxAttributes(attributes);

      IAjaxCallListener blockingListener = new AjaxCallListener() {
        @Override
        public CharSequence getPrecondition(Component component) {
          return "console.log('getPrecondition');";
        }
        @Override
        public CharSequence getSuccessHandler(Component component) {
          return "console.log('getSuccessHandler');";
        }
      };
      attributes.getAjaxCallListeners().add(blockingListener);
    }
  };
  add(blockingLink);
 }
}

1 个答案:

答案 0 :(得分:0)

使用案例:阻止直到Ajax请求完成,请参阅http://my.safaribooksonline.com/book/-/9781849511605/deeper-into-ajax/ch07lvl1sec04 (第162页)

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
  super.updateAjaxAttributes(attributes);
  attributes.setChannel(new AjaxChannel("myChannel", AjaxChannel.Type.ACTIVE));
}

完成了这项工作。见wicket forum