14.5. Programmatically firing events

You likely won’t have many occasions where you want to programmatically create native events. Most often it’s in test cases for your own widgets. (Because Google constantly tests GWT widgets, there’s limited benefit in testing them yourself. In fact, it’s positively encouraged not to test GWT widgets because UI testing is heavy compared to functionality testing—that could be a whole chapter on its own!)

But if you find yourself in a situation where you have to programmatically fire native events, then you do so as follows. First, you need to get the event from the Document; for example, the following listing shows firing a keypress event on a TextBox.

Listing 14.5. Programmatically firing a keypress event ...

Get GWT in Action, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.