class sap.ui.model.odata.type.String

Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/ui/model/odata/type/String
Application Component: CA-UI5-COR

This class represents the OData primitive type Edm.String.

In both sap.ui.model.odata.v2.ODataModel and sap.ui.model.odata.v4.ODataModel this type is represented as a string.


Constructor

Constructor for an OData primitive type Edm.String.

new sap.ui.model.odata.type.String(oFormatOptions?, oConstraints?)
Param Type Default Value Description
oFormatOptions? object

format options as defined in the interface of sap.ui.model.SimpleType

parseKeepsEmptyString? boolean false

if true, the empty string "" is parsed to "" and nullable=false does not mean "input is mandatory". Otherwise the empty string "" is parsed to null which might be rejected.

oConstraints? object

constraints; validateValue throws an error if any constraint is violated

isDigitSequence? boolean string false

if true, the value is handled as a sequence of digits; while formatting leading zeros are removed from the value and while parsing the value is enhanced with leading zeros (if a maxLength constraint is given) or leading zeros are removed from the value (if no maxLength constraint is given); this constraint is supported since 1.35.0.

To make this type behave as ABAP type NUMC, use oConstraints.isDigitSequence=true together with oConstraints.maxLength.

A type with isDigitSequence=true and nullable=false does not parse the empty string to null or "", but to "0" instead. This overrides parseKeepsEmptyString and means that "input is mandatory" does not hold here.

maxLength? int string

the maximal allowed length of the string; unlimited if not defined

nullable? boolean string true

if true, the value null is accepted. The constraint nullable=false is interpreted as "input is mandatory"; empty user input is rejected then (see parseKeepsEmptyString and isDigitSequence for exceptions).


Methods Overview

Method Description
sap.ui.model.odata.type.String.extend

Creates a new subclass of class sap.ui.model.odata.type.String with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.model.odata.type.ODataType.extend.

formatValue

Formats the given value to the given target type. If the isDigitSequence constraint of this type is set to true, the target type is 'any' or 'string', and the given value contains only digits, the leading zeros are truncated. If the isDigitSequence constraint of this type is set to true and the maxLength constraint is set, this type behaves as an ABAP type NUMC; in this case, the value '0' is formatted to '', provided the target type is 'string'.

sap.ui.model.odata.type.String.getMetadata

Returns a metadata object for class sap.ui.model.odata.type.String.

getName

Returns the type's name.

parseValue

Parses the given value which is expected to be of the given type to a string. If isDigitSequence constraint of this type is set to true and the parsed string is a sequence of digits, then the parsed string is either enhanced with leading zeros, if maxLength constraint is given, or leading zeros are removed from parsed string.

Note: Depending on the format option parseKeepsEmptyString, an empty input string ("") is either parsed to "" or null. If the constraint nullable is false, a null value is rejected with a ValidateException raised in the #validateValue method.

validateValue

Validates whether the given value in model representation is valid and meets the defined constraints.

sap.ui.model.odata.type.String.extend

Creates a new subclass of class sap.ui.model.odata.type.String with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.model.odata.type.ODataType.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

formatValue

Formats the given value to the given target type. If the isDigitSequence constraint of this type is set to true, the target type is 'any' or 'string', and the given value contains only digits, the leading zeros are truncated. If the isDigitSequence constraint of this type is set to true and the maxLength constraint is set, this type behaves as an ABAP type NUMC; in this case, the value '0' is formatted to '', provided the target type is 'string'.

Param Type DefaultValue Description
sValue string

the value to be formatted

sTargetType string

the target type; may be "any", "boolean", "float", "int" or "string". See sap.ui.model.odata.type for more information.

sap.ui.model.odata.type.String.getMetadata

Returns a metadata object for class sap.ui.model.odata.type.String.

getName

Returns the type's name.

parseValue

Parses the given value which is expected to be of the given type to a string. If isDigitSequence constraint of this type is set to true and the parsed string is a sequence of digits, then the parsed string is either enhanced with leading zeros, if maxLength constraint is given, or leading zeros are removed from parsed string.

Note: Depending on the format option parseKeepsEmptyString, an empty input string ("") is either parsed to "" or null. If the constraint nullable is false, a null value is rejected with a ValidateException raised in the #validateValue method.

Param Type DefaultValue Description
vValue string number boolean

the value to be parsed

sSourceType string

the source type (the expected type of vValue). See sap.ui.model.odata.type for more information.

validateValue

Validates whether the given value in model representation is valid and meets the defined constraints.

Param Type DefaultValue Description
sValue string

the value to be validated