Tuesday, November 10, 2009

Notify when Bean property changed

We want to know or to get notified when the bean property is changed. For that we create a Bean having a property named name with getter/setter method.

First we need a PropertyChangeSupport field to the bean, with this object we will fire the property change event. When we need to listen for the change we have to create an implementation of a PropertyChangeListener. In this example we'll just use the MyBean class as the listener.

The PropertyChangeListener has a method called propertyChange and inside this method we'll implementing the code to get the event fired by the PropertyChangeSupport.

No comments:

Post a Comment