views:

131

answers:

2

Hi, Everything is in the title of the question. Can you provide some use case we use PropertyChangeListener and VetoableChangeListener ?

A: 

A vetoable change listener can veto (forbid) the property change. It will be rolled back if the receiver wishes. You may also attach constraints to the changed property. http://java.sun.com/j2se/1.4.2/docs/api/java/beans/VetoableChangeListener.html

Simon
+1  A: 

The main difference resides in the fact that PropertyChangeListener are applied to bound properties while VetoableChangeListener are applied to constrained properties.

A bound property is just a property, while a constrained property is a property on which listeners can express themselves about a change that is going to be made: they can refuse this change from happening.

What it actually happens is that when you notify a vetoable property change you will do something like

VetoableChangeSupport vcs;
vcs.fireVetoableChange(...);

and this can throw a PropertyVetoException which will tell your bean that an observer wishes to block this property change (it should be rolled back).

Jack