GWT (Google Web Toolkit) Tips

Tuesday, July 17, 2007

Passing Events instead of Widgets to Listeners in the Google Web Toolkit (GWT)

Level: Advanced
Date: Originally published 10/07
Author: Richard Bondi,

In GWT, a listener object A may attach itself to many other widgets. These widgets will call A's onChange (or similar) method, and pass themselves as onChange's only parameter. Inside onChange, A must then decide which widget called it. The problem at this point is for a programmer unfamiliar with the code: there is no easy way for her to tell which of the widget's many methods and properties are intended to be used by A. The solution given here is to create an interface, named [widget's name]Event, that has only methods to be used inside of onChange. This makes for clean and understandable code.

The full text of this post is available at http://docs.google.com/Doc?id=dw2zgx2_331ns4qh527.

No comments:

About this blog

Notes on the Google Web Toolkit and RoR.