Wicket 6.1 AjaxEventBehavior - how to set delay? Wicket 6.1 AjaxEventBehavior - how to set delay? ajax ajax

Wicket 6.1 AjaxEventBehavior - how to set delay?


Setting the throttle's settings has been unified with all other Ajax settings in AjaxRequestAttributes for version 6.0.0 which is a major version and was not drop-in replacement.

https://cwiki.apache.org/confluence/display/WICKET/Wicket+Ajax contains a table with all the settings, the throttling ones are mentioned at the bottom of it.

To use it :

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)        );    }};

The last constructor argument is what you need. Check its javadoc.


Looking at the sources, it looks as you can get the AjaxRequestAttributes via getAttributes() and call setThrottlingSettings() on this.

Strange that the api change is not mentioned in the wiki. The announcement for 6.1 calls it an drop in replacement.


It seems that drop behavior is what you're after:

dropping - only the last Ajax request is processed, all previously scheduled requests are discarded

You can specify a drop behavior, that will only for the Ajax channel by customizing the AjaxRequestAttributes of the behavior with AjaxChannel.DROP by means of updateAjaxAttributes, as pointed out in the wiki:

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.setChannel(new AjaxChannel("myChannel", AjaxChannel.Type.DROP));    }};form.add(behavior); 

As @bert also suggested, you can also setThrottlingSettings to the AjaxRequestAttributes.

Probably a combination of both behaviors would fit better in what you seem to need.