0
votes

I'd like to run a small piece of javascript code for every component of a list. Right now I output the code in the onRenderHead() callback of a behavior attached to each component:

public class MyBehavior extends Behavior {
  @Override
  public void renderHead(Component component, IHeaderResponse response) {
    response.render(OnDomReadyHeaderItem.forScript(
        String.format("my_js_callback('%s')", component.getMarkupId())));
  }
}

This works fine.

However now I ajax-refresh the list of component (potentially adding or removing components in the list). How can I make sure the behavior javascript code get called for each component after this ajax-refresh? Is there an easy "wicket way" of doing this? Or should I call some hand-crafted method passing the AjaxRequestTarget context on the way?

2

2 Answers

1
votes

In fact it's rather simple: the javascript code installed by OnDomReadyHeaderItem.forScript() is called also after an ajax refresh. My initial question is rather irrelevant: nothing is necessary to make it work.

(Wicket really rocks.)

0
votes

I'd suggest to move the javascript code at list level. The list itself can execute the needed javascript for every component it has. You should solve you problem with AJAX refresh using an AjaxCallListener attached to the list. With this class you can specify the js code to execute when the ajax request has been completed. More details can be found here.