TurboManage

David Chandler's Journal of Java Web and Mobile Development

GWT PropertyChangeListeners come full circle with MVP

Posted by David Chandler on October 6, 2009

I initially stumbled on the excellent Model-View-Presenter pattern for GWT while wading through discussion threads on the various library options for PropertyChangeSupport (since GWT does not offer it natively). In the process, I’ve found that I’m unable to completely avoid the need to store a few things in a client-side model, and the model turns out to be the most convenient place to fire an event indicating that the model has been updated, which looks an awful lot like…a PropertyChangeEvent/Listener.

	void setPrayerLists(List<PrayerList> prayerLists)
	{
		this.prayerLists = prayerLists;
		// Hah, we're back to PropertyChangeListeners, after all
		eventBus.fireEvent(new PrayerListsModifiedEvent(prayerLists));
	}

Of course, the event now being fired is now my own, not a PropertyChangeEvent, so I no longer need a PropertyChangeSupport emulation library and no longer have to worry about the accompanying idiosyncracies involving collections, etc. And thanks to GWT’s HandlerManager and related classes, I can fire events for any purpose, not just PropertyChangeEvents, and the event can carry a payload such as accompanying data in its constructor. I just mean to say that firing events off model changes still turns out to be useful in some cases. And I somehow find that humorous.

Leave a comment