Friday, February 25, 2011

Screencast: GWT Event Bus Basics

Wheee! I made a screencast. Happy Friday to you too.

This screencast is about the GWT Event Bus. It explains how an Event Bus can be used to loosely couple controllers or views in MVC applications, and includes live coding of a GWT using the SimpleEventBus client. The source is all available on GitHub. And as always, up votes are appreciated.

If it doesn't play correctly, you may want to launch it from the site.

"This screencast explains why MVC applications benefit from an event bus, and it demonstrates how to create, wire, and respond to events in Google Web Toolkit (GWT). Not bad for just six and a half minutes." Too much fun.


Sven said...

Hi Hamlet!

But where do you really have trouble with Controller coupling in real life?

Is GWT a common candidate? Swing?


Hamlet D'Arcy said...

most my MVC experience is Swing. Windows are always needing to talk to each other, and without an event bus I always end up giving the controllers references to each other or making a "Manager" interface that controllers implement. In GWT we always used the EventBus, so I had no issues.

So Swing... hand-rolled Swing MVC.

WenZ said...

Hi Hamlet!!

Thanks for the tutorial. It was just great to help all GWT beginners to get the event bus concept right.

I just have a question. Let's say I have 2 buttons, each one generates a different event. For exammple, a "Save" button and a "Cancel" button which fire 2 different kind events.
Does that mean that :
1) I have to write 2 classes: "SaveEventHandler" and "CancelEventHandler",
2)I can have those 2 events grouped in the same "AllEventHandler" and have onSaveEvent and onCancelEvent? But i don't understand how the application will know which event it is.

Please help.
Thank you :)

Hamlet D'Arcy said...


As far as I know, an event is tied to a specific handler. So you would need to handlers and two events in your case. However, nothing stops you from putting enough data into the event class so that your handler can tell two different events apart. Overall though, I would use two different events.