Return to Snippet

Revision: 11283
at January 30, 2009 08:17 by ronaldtm


Initial Code
new AjaxButton("save") {
    @Override
    protected IAjaxCallDecorator getAjaxCallDecorator() {
        return new DisableComponentCallDecorator(super.getAjaxCallDecorator(), this);
    }
}

class DisableComponentCallDecorator extends AjaxPreprocessingCallDecorator {
    private final String selector;
    private DisableComponentCallDecorator(IAjaxCallDecorator delegate, String jquerySelector) {
        super(delegate);
        this.selector = jquerySelector;
    }
    private DisableComponentCallDecorator(IAjaxCallDecorator delegate, Component component) {
        super(delegate);
        component.setOutputMarkupId(true);
        this.selector = "#" + component.getMarkupId();
    }
    @Override
    public CharSequence preDecorateScript(CharSequence script) {
        return "$('" + selector + "').addClass('disabled_while_waiting').attr('disabled','disabled'); " + super.preDecorateScript(script);
    }
    @Override
    public CharSequence preDecorateOnSuccessScript(CharSequence script) {
        return "$('" + selector + "').removeAttr('disabled'); " + super.preDecorateOnSuccessScript(script);
    }
    @Override
    public CharSequence preDecorateOnFailureScript(CharSequence script) {
        return "$('" + selector + "').removeAttr('disabled'); " + super.preDecorateOnFailureScript(script);
    }
}

Initial URL

                                

Initial Description

                                

Initial Title
Before-submit scripts for Wicket's AjaxButton

Initial Tags
ajax, javascript

Initial Language
Java