Bound Properties
In
the previous example, property changes can take place when one of the
setStocks() methods are invoked. This results in
the state of the WatchList being changed. What
would happen if two objects were using the
WatchList and one of them changed the
Stocks property? It’s possible that users
of the WatchList will want to know if its
properties are changed.
A Bean component can provide change notifications for its properties. These notifications take the form of events, and they conform to the event model described in the earlier chapters. Properties that support change notifications are known as bound properties, because other objects can bind themselves to changes in their value.
Non-Specific Property Binding
An object can bind itself to non-specific property changes. In this
case the source object sends notifications to the bound object
whenever the value of one of its bound properties has changed. The
notification takes the form of a
java.beans.PropertyChangeEvent. The public methods
for this class are shown below, without their implementations:
public class java.beans.PropertyChangeEvent extends java.util.EventObject { // contructor PropertyChangeEvent(Object source, // the source of the event String propertyName, // the property name Object oldValue, // the old value Object newValue); // the new value // get the new value of the property public Object getNewValue(); // get the old value of the property public Object getOldValue(); // get the event propagation ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access