Question

I have been requested to upgrade the wicket version from 1.5.9 to 6.14.0 in a web-app. I have found upgrading the (behavior) decorators to listeners very problematic.

https://cwiki.apache.org/confluence/display/WICKET/Wicket+Ajax#WicketAjax-o.a.w.ajax.IAjaxCallDecoratorisreplacedwitho.a.w.ajax.attributes.IAjaxCallListener

o.a.w.ajax.IAjaxCallDecorator is replaced with o.a.w.ajax.attributes.IAjaxCallListener.

I have succeeded in creating a POC where I upgrade the needed parts almost correctly.

In 1.5.9 the element script can be decorated like this (at low level, there is also other changes involved, but it ends to this)

public class MyBehavior extends AjaxFormComponentUpdatingBehavior {

  @Override
  // (removed in upgrade to 6.14.0)
  protected IAjaxCallDecorator getAjaxCallDecorator() {
    return new SmallDecorator();
  }

  private class SmallDecorator extends AjaxCallDecorator {
    public SmallDecorator() {}

    @Override
    public CharSequence decorateScript(Component component, CharSequence script) {
        return "alert('decorated onblur');" + script;
    }
  }
}

In 6.14.0 the same is done like this (as far as I have understood it correctly)

public class OnBlurBehavior extends AjaxFormComponentUpdatingBehavior {

  @Override
  protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    attributes.getAjaxCallListeners().add(new
    GenericListenerImpl("alert('Listener onblur')"));
  }

  private class GenericListenerImpl extends AjaxCallListener {
    private String decoratorScript = null;
    public GenericListenerImpl(String decoratorScript) {
      this.decoratorScript = decoratorScript;
    }

    @Override
    public CharSequence getPrecondition(Component component) {
      return this.decoratorScript;
    }
  }
}

Now this works in basic, but when I want to edit or wrap the "script" like in the 1.5.9 version is done, how can I accomplish that in the 6.14.0 version?

This has proved to me extremely problematic as I haven't used Wicket for a (very) long time and kind of being a noob is specially what comes to the latest version. :)

Was it helpful?

Solution

I was in impression that the "script" part in 1.5.9 contains a single String of element attributes (or something like that) UI developer had added for the element in html. But checking that in detail reveals that the "script" content actually looks something like this:

var wcall=wicketAjaxPost('./?0-1.IBehaviorListener.0-input', wicketSerialize(Wicket.$('input')),function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$('input') != null;}.bind(this));

So the "script" is something generated by the wicket and actually there is no content that could had been set by the (UI) developer and could require modification on the java side.

In general I consider such behavior bad (as in 1.5.9) when given the generated script to be modified and omitting this option alltogether in upgrade to 6.14.0 seems justified... Even that this causes gray hair and extra work to fix the functionality getting broken with the upgrade.

The code examples given above are correct, you just need to figure out what behavior to add (override) in GenericListenerImpl to gain the same functionality as with decorating the script with SmallDecorator.

The API for AjaxCallDecorator appears to be bad as it does not explaing the parameters with the 'decorateScript', thus I was mislead with the issue...

http://wicket.apache.org/apidocs/1.5/org/apache/wicket/ajax/calldecorator/AjaxCallDecorator.html#decorateScript%28org.apache.wicket.Component,%20java.lang.CharSequence%29

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top