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;

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

        @Override
        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 :

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                super.updateAjaxAttributes(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.

Hendy





--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Make-default-AjaxChannel-Type-to-ACTIVE-tp4661047.html
Sent from the Forum for Wicket Core developers mailing list archive at 
Nabble.com.

Reply via email to