Joel Fontaine-Richard
Joel Fontaine-Richard

Reputation: 107

gwt listbox execute my handler

I have a listbox with a changeHandler attached to it. In this changehandler, there are some very important verifications that I dont want to copy, to keep my code clean.

 this.myListBox.addChangeHandler(this.myChangeHandler);

 private ChangeHandler myChangeHandler = new ChangeHandler() {
    @Override
    public void onChange(ChangeEvent event) {
       If (a<0)...
    }
 }

I used to have a ChangeListener with onChange(Widget sender) but it is now deprecated. With the listener I had it was easy to execute the ChangeListener with:

this.myChangeListener.onChange(this.myListBox);

How can I execute the onChange(ChangeEvent event) of my new ChangeHandlereven when the user does not touch the listbox? (to make the verifications happen)

Upvotes: 0

Views: 219

Answers (2)

El Hoss
El Hoss

Reputation: 3832

You can try to fire a native event:

DomEvent.fireNativeEvent(Document.get().createChangeEvent(), myListBox);

Upvotes: 0

Fedy2
Fedy2

Reputation: 3207

ChangeEvent can't be instantiated because is a native event. You can create a class that implements ChangeHandler and put the onChange logic in a public method (validate) that accepts the ListBox as argument. Then from onChange method you call the new validate method. If you want to use it "manually" you can simply call validate.

Upvotes: 2

Related Questions