Caps
Caps

Reputation: 1523

Manually calling a wicket event handler for a component

I'm working on a Wicket application and I've defined an onchange event handler for a DropDownChoice and I'd like to manually call the handler. Does anyone know of a way to do this?

Code example:

DropDownChoice<String> choices = new DropDownChoice<String>(
  "choices",
  new Model<String>(),
  Arrays.asList("First", "Second", "Third");

choices.add(new AjaxFormComponentUpdatingBehavior("onchange") {
  @Override
  protected void onUpdate(AjaxRequestTarget target) {
    // do stuff
  }
});

I know that I could do pull the contents of onUpdate out into it's own method and just call that method but I'm curious to know whether there is a way the event handler directly.

I know WicketTester can simulate a component being clicked or changed. Perhaps the way it does it would work?

Cheers,

Caps

Upvotes: 2

Views: 4761

Answers (2)

Oğuz &#199;am
Oğuz &#199;am

Reputation: 31

To call it from JavaScript or Jquery, you can call

htmlElement.trigger("change");

It is calling AjaxFormComponentUpdatingBehavior("onchange") in Wicket 1.6.

Upvotes: 0

Nicktar
Nicktar

Reputation: 5575

In Wicket 1.5 there is an eventbus for such use cases. In prior versions, you'll have to emulate this. There are other questions related to this. (See here)

Upvotes: 2

Related Questions