Skip to content

Attribute Value Change Handling

pm4j edited this page May 9, 2012 · 6 revisions

Calls to the PmAttr methods setValue() and setValueAsString() trigger a value change operation (if the attribute is enabled).

pm4j offers some support to control value changes and to trigger other changes in relation to a value change.

Before- and after-change methods

Attribue specific value change control may be implemented by overriding the following methods:

  • boolean beforeValueChange(oldValue, newValue) and
  • void afterValueChange(oldValue, newValue) (TODO: Link to JavaDoc)

The implementation of beforeValueChange() may prevent the value change by returning false.

Value change decorator

A PmAttrValueChangeDecorator may be used to define value change logic that should be applied for multiple attributes.

It may also be used to add some logic an attribute provided by another PM-class or module.

A decorator may be added to the attribute value changed processing by calling:

  • PmEventApi#addValueChangeDecorator(pmAttr, decorator)

Sample code

The following unit test may be used as an example for attribue value change handling: