3

I was asked to upgrade one of our existing applications, and I am having a bit of trouble figuring out how to update some of our classes.

We have our own CustomAjaxButton class which extends AjaxButton, in which the getAjaxCallDecorator is overridden so we can return a custom decorateOnSuccessScript etc.

I found the https://cwiki.apache.org/confluence/display/WICKET/Wicket+Ajax#WicketAjax-o.a.w.ajax.IAjaxCallDecoratorisreplacedwitho.a.w.ajax.attributes.IAjaxCallListener. page which does explains the why, but I am unsure how to combine this with the new AjaxButton implementation since getAjaxCallDecorator has been removed.

Code snippet of the old version:

@Override
    protected IAjaxCallDecorator getAjaxCallDecorator() {
        return new IAjaxCallDecorator()
        {
         private static final long serialVersionUID = 6L;
...
         public CharSequence decorateScript(CharSequence script)
         {
          return script + " document.getElementById('inputBlocker').style.display='none';";
         }
        };
    }

I have to admit I an quite new at Wicket, and my more experienced colleague is on vacation. Any help\advice is much appreciated.

Kate Danes
  • 63
  • 6

1 Answers1

6

Try this approach:

add(new AjaxLink("btn"){

    @Override
    protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
        super.updateAjaxAttributes(attributes); 
        attributes.getAjaxCallListeners().add(new AjaxCallListener(){

            @Override
            public CharSequence getSuccessHandler(Component component) {
                return " document.getElementById('inputBlocker').style.display='none';";
            }

        });
    }

});

In the AjaxCallListener you can override any handler you want. If you want you can change the script execution to the complete handler

Robert Niestroj
  • 15,299
  • 14
  • 76
  • 119