开发者

What is the difference between PropertyChangeListener and VetoableChangeListener?

开发者 https://www.devze.com 2022-12-30 09:36 出处:网络
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 Prope

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号