What is the difference between PropertyChangeListener and VetoableChangeListener?
Everything is in the title of the question. Can you provide some use case we use PropertyChan开发者_运维知识库geListener and VetoableChangeListener ?
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).
A VetoableChangeListener can veto (forbid) the property change. It will be rolled back if the receiver wishes. You may also attach constraints to the changed property.
精彩评论