Behavior Binding

QName: f:behavior-binding

Marks an association as pointing to the implementation of a behavior for a policy on the source node. Valid target nodes include script nodes and rules. By applying this feature, you indicate that the target node script or rule should execute when the policy triggers.

The target node (script or rule) must implement the f:behavior feature.

For example, you might upload a JavaScript file that provides an implementation of a method to handle the afterNodeUpdate event. The association linking the content instance (or type) to the behavior should have this association indicating the policy method being overridden (afterNodeUpdate).

Configuration

Property Type Default Read-Only Description
policy text The QName of the node policy being bound to.
property text Optional property name if the policy binding is to a property, otherwise empty.
scope number Defines the scope of the binding. To bind to a specific instance, set to 0. To bind to all instances of a class type, set to 1.

Behavior Binding Example

To demonstrate this feature, we need three JSON objects - a content node, a behavior and the binding (association).

The content node might be as simple as this:

{
    "title": "My Content Instance"
}

And the behavior might be some JavaScript that you upload. The JavaScript might be:

function beforeUpdateNode(node)
{
    node.data["testProperty"] = "testValue";
}

And the JavaScript's node should indicate that it is a behavior, like this:

{
    "_features": {
        "f:behavior": {
        }
    }
}

Finally, we have an association between the content node and the behavior. The association indicates the policy being bound to. It might look like this:

{
    "_features": {
        "f:behavior-binding": {
            "policy": "p:beforeUpdateNode",
            "scope": 0
        }
    }
}