Show TOC

UI Control ConstructorsLocate this document in the navigation structure

A constructor is a special type of function that is called to create an object. The constructor uses values to set control properties, thus preparing the new object for use.

In SAPUI5, control constructors accept the following arguments in the specified order:

  1. An optional unique identifier of type string which must either be the first argument, or omitted altogether. If you omit the ID, the SAPUI5 framework automatically computes an ID. Specifying your own identifier allows your application to easily find the control and, for example, retrieve the current user input from it. Alternatively, you can keep a reference to the control in a variable.
  2. One JSON-like object (object literal) as mSettings parameter that defines values for any property, aggregation, association, or event. If a specific name for a control is ambiguous, meaning that a property has the same name as an event, the framework assumes in the following order: Property, aggregation, association. To resolve ambiguities, add the respective prefix to the key in the JSON object: "aggregation:", "association:", or "event:".

The following code snippet shows an example of a constructor that is called to create a new text field "Hello World" with the specified tooltip and width:

var oTextField = new sap.ui.commons.TextField("testTextField",
     {value : "Hello SAPUI5", tooltip: "This is an example tooltip", width: "100px"});

The above example is an abbreviated version of the following code snippet with a detailed list of statements, which is alternatively supported:

var oTextField = new sap.ui.commons.TextField("testTextField"); 
    oTextField.setValue("Hello SAPUI5");
    oTextField.setTooltip("This is an example

The supported parameters are documented in the JsDoc of the respective control.