Reputation: 1523
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
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