Wicket 6.1 AjaxEventBehavior - 如何设置延迟?

st6*_*6mm 6 java ajax wicket

AjaxEventBehavior behavior = new AjaxEventBehavior("keyup"){

    @Override
    protected void onEvent(AjaxRequestTarget target) {

        System.out.println("Hello world!");
    }
};

form.add(behavior); 
Run Code Online (Sandbox Code Playgroud)

在以前版本的Wicket中,我可以这样做:

behavior.setThrottleDelay(Duration.ONE_SECOND);
Run Code Online (Sandbox Code Playgroud)

但自6.1版以来,这个机会已被抹去.Web上充满了以前版本的教程,这些教程都包含.setThrottleDelay()方法.

基本上,目标是在人员停止在表单中键入时调出行为.目前,每当密钥启动时,它每次都会调用该行为,这基本上会阻塞服务器端.这就是我想延迟的原因.背景:我目前正在尝试对数据库进行查询,并获取与表单输入类似的数据.在这个人打字的时候,所有这一切.但是目标是需要延迟以使服务器端/ SQL退出"轰炸范围".

我也愿意接受替代方案.

mar*_*n-g 9

设置限制的设置已经与版本6.0.0的AjaxRequestAttributes中的所有其他Ajax设置统一,这是一个主要版本,并不是直接替换.

https://cwiki.apache.org/confluence/display/WICKET/Wicket+Ajax包含一个包含所有设置的表格,其底部提到了限制的表格.

要使用它:

AjaxEventBehavior behavior = new AjaxEventBehavior("keyup") {

    @Override
    protected void onEvent(AjaxRequestTarget target) {
        System.out.println("Hello world!");
    }
    @Override
    protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
        super.updateAjaxAttributes(attributes);
        attributes.setThrottlingSettings(
            new ThrottlingSettings(id, Duration.ONE_SECOND, true)
        );
    }
};
Run Code Online (Sandbox Code Playgroud)

最后一个构造函数参数是您需要的.检查它的javadoc.

  • 请检查您的代码,似乎缺少一个`{`。 (2认同)