Skip to content

Attribute Default Values

olaf-boede edited this page Oct 28, 2013 · 5 revisions

PmAttr's may be configured to have default values if their backing value is null.

The default value feature is intended for edit use cases.
This means: Default values will only be applied for enabled attributes.

Static definition (string value based)

You may pass the default value using a string.

  @PmAttrCfg(defaultValue="...")

The annotation uses the type specific string format as used for PmAttr.setValueAsString().
In case of enums it's the enum literal name, in case of a boolean attribute 'true' or 'false'...

Dynamic definition (type safe)

You may override the method getDefaultValueImpl() to provide a java based default value logic. An example

  PmAttrBoolean myAttr = new PmAttrBooleanImpl(this) {
    protected Boolean getDefaultValueImpl() { return Boolean.TRUE; }

Some implementation details

The default value will be applied to the attribute when a getValue() call detects that the attribute has no value.
(Remark: Each attribute may define it's 'no value' condition by implementing isEmptyValue().)

The getValue() method calls in this case the method setBackingValue(defaltValue) to apply the default. The attribute is not marked as changed when a default value was applied.