Make default AjaxChannel.Type to ACTIVE ?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Make default AjaxChannel.Type to ACTIVE ?

Hendy Irawan
I recently hit by double/repeated submission problem due to AjaxChannel.Type defaults to ACTIVE.

So we're using a Modal which submits a form using an AjaxButton, markup using

However this enables the user to double/multi-click the button, hence multi-submitting the form.

We tried to circumvent this by disabling the button/link during AJAX call :

 * Disables the component via JavaScript before AJAX, and re-enables it again after AJAX success or failure.
 * Note that you still need to use a {@link AjaxChannel.Type#ACTIVE} {@link AjaxChannel}, because the default
 * is {@link AjaxChannel.Type#QUEUE}.
 * @see AutoDisableAjaxButton
 * @author rudi
public class AutoDisableAjaxCallListener extends AjaxCallListener {

        private static final long serialVersionUID = 1L;

        public CharSequence getPrecondition(Component component) {
                return "if ($(this).attr('disabled') != undefined) return false;\n" + super.getPrecondition(component);
        public CharSequence getBeforeSendHandler(
                        Component component) {
                return "$(this).attr('disabled', 'disabled');\n" + super.getBeforeSendHandler(component);

        public CharSequence getCompleteHandler(
                        Component component) {
                return super.getCompleteHandler(component) + "\n$(this).attr('disabled', " + (component.isEnabledInHierarchy() ? "null" : "'disabled'") + ");";


However this doesn't work as intended because Wicket queues the AJAX call, so multi clicks will still submit multiple times.

We need to use AjaxChannel.Type.ACTIVE :

        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                attributes.setChannel(new AjaxChannel("autodisable", AjaxChannel.Type.ACTIVE));
                attributes.getAjaxCallListeners().add(new AutoDisableAjaxCallListener());

I wonder why this defaults to QUEUE, since QUEUE results in double submission.

Using ACTIVE already prevents double submission, with or without AjaxCallListener. (since AjaxCallListener impl above is mostly cosmetic, the behavior is still defined by AjaxChannel)

I'd propose a change of default for Wicket 7.0 if the reason is accepted.