docs

Aggregation Forwarding

A mechanism used for aggregations of composite controls.


Overview

Aggregration forwarding is used when application developers want to add child controls to an aggregation of a composite control, but the composite control does not keep these controls as direct children. Instead, it moves or forwards them to an aggregation of one of its internal controls.

This technique is often used when a control with an aggregation is wrapped by a composite control to add functionality, but the application still has control over the content of the wrapped control. In other cases, the composite control uses layout controls internally to define the placement of aggregated children.

Note:

While aggregation forwarding as described here is mainly aimed at composite controls, it has also been implemented for the ManagedObject base class. The forwarding can also be used for other entities which are not controls, but inherit directly from ManagedObject or one of its subclasses.

For more information about this class, see the API Reference: ManagedObject.

Note:

Sometimes the controls that have been added to an aggregation of a composite control have to be transformed into different controls, which are then added to an aggregation of an internal control. This is a different use case and not covered by aggregation forwarding. With aggregation forwarding, aggregated child controls are moved without transforming them.


Configuration

Aggregation forwarding requires a simple additional setting in the definition of a control aggregation. OpenUI5 needs to know to which internal control all aggregated children need to be forwarded and to which aggregation of this internal control.

Aggregation forwarding is defined in the aggregation definition inside the control metadata.

The forwarding property can be set as an object defining the following:

When such a forwarding definition is done, OpenUI5 moves all aggregated child controls to the target control. All calls to addAggregation, removeAggregation, indexOfAggregation and so on are forwarded. When asked for the forwarded child control, both the composite control and the forwarding target act like the child control belongs to their aggregation. However, the inner forwarding target control is the actual parent of all forwarded children.


Examples

Here is an example that demonstrates aggregation forwarding: The new FilterableList control is supposed to display a list of items with an input field above the list. The list items are filtered while the user is entering the input. This FilterableList control can be implemented as a composite control, using the sap.m.List and sap.m.Input controls as inner controls to take advantage of their existing implementation, design, and set of features. Application developers using FilterableList cannot change all attributesof the inner List control. However, they should be able to provide the actual list items. Hence, the new FilterableList composite control has an items aggregation and forwards all items to the inner sap.m.List control, so, for example, the layouting, events, and selection can be handled there.


aggregations: {
	 // The items forwarded from the FilterableList to the internal sap.m.List
	 items : {type: "sap.m.ListItemBase", multiple: true, forwarding: {
		   idSuffix: "-myInternalList",
		   aggregation: "items"
	 }},

Another example would be a new ButtonList control that is supposed to contain and display an arbitrary number of sap.m.Button controls in a grid. Hence it has a buttons aggregation. For this control, control-specific HTML could be written that provides screen-size-dependent CSS for a proper grid layout of the buttons. However, this effort can be avoided, and a sap.ui.layout.Grid control used internally instead to do the layouting. The buttons given to the ButtonList control then need to be forwarded to the content aggregation of the Grid control.


aggregations: {
	 // The items forwarded from the ButtonList to the internal sap.ui.layout.Grid
	 buttons: {type: "sap.m.Button", multiple: true, forwarding: {
		   getter: "_getInternalGrid",
		   aggregation: "content"
	 }},

Aggregation Forwarding in XML Composite Controls (Deprecated)

If you use aggregation forwarding with idSuffix for an XML composite control (deprecated), you define this as follows:

sap.ui.define([
    "sap/ui/core/XMLComposite"], 
    function( XMLComposite ) {
    "use strict";
    var TextList = XMLComposite.extend("fragments.TextList", {
        metadata: {
            aggregations: {
                texts: { 
                    type: "sap.ui.core.Item",
                    multiple: true, forwarding: {
                           idSuffix: "--myInternalVBox",
                           aggregation: "items"
                     }
                }
            }
        }
    })
    return TextList;
});

In this case, the fragment definition XML file looks like this:

<core:FragmentDefinition xmlns:m="sap.m" xmlns:core="sap.ui.core">
    <m:VBox id="myInternalVBox"/>
</core:FragmentDefinition>

Note:

myInternalVBox is prefixed with --. Other than that, the coding looks exactly the same as the one for aggregation forwarding for standard composite controls.


Dos and Don’ts

If you use aggregation forwarding, you have to keep the following in mind: