I notice that there are two methods by which an event handler can be hooked up to a GWT widget: addHandler and addDomHandler. The JavaDoc for addDomHandler says, “Adds a native event handler to the widget and sinks the corresponding native event. If you do not want to sink the native event, use the generic addHandler method instead.”
I’d be very grateful if someone would enlighten me as to the difference between native events and logical events.
Native events are fired directly by the browser – events like clicks, mouseovers, keypresses, etc. To receive those events on a Widget, you have to specifically sink the events.
The generic events are, well, more generic. For example, I’ve created a
SaveEventand aDeleteEventfor my own use, that get fired when certain UI conditions are met. They are farther away from the browser and would never get fired directly by the browser. I think you should stick with the more generic events when you can. On the other hand, if you’re creating a custom widget that you can’t make out of other widgets – for example, if you want to build a slider that the user can click and drag – you’ll need the DOM events.