Handling Events for Specific Properties
If a Bean component supports bound
properties, it is required to support the binding mechanism described
earlier. This means that it must provide an
addPropertyChangeListener()
method for any client object that wants to
receive bound property changes via the
PropertyChangeListener interface. The same holds
true for constrained properties. In that case, the Bean must provide
an
addVetoableChangeListener()
method for any client object that wants to
receive VetoableChangeEvent notifications via the
VetoableChangeListener interface. But the Bean
also has the option of providing specific registration methods for
listeners to register for property change and vetoable change
notifications for specific properties. There is no requirement to
support these mechanisms, but they may be useful under some
circumstances.
There is a design pattern for registering and unregistering event listeners for changes to specific bound properties. The method signatures are as follows:
public void add<PropertyName>Listener(PropertyChangeListener p); public void remove<PropertyName>Listener(PropertyChangeListener p);
There is also a design pattern for registering and unregistering event listeners for vetoable change events for specific constrained properties. The method signatures are as follows:
public void add<PropertyName>Listener(VetoableChangeListener p); public void remove<PropertyName>Listener(VetoableChangeListener p);
This is convenient if a source object supports ...
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