abstract class sap.ui.model.SimpleType

Control sample: sap.ui.model.SimpleType
Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/ui/model/SimpleType
Application Component: CA-UI5-COR

This is an abstract base class for simple types. A simple type can format a raw model value based on the given format options, parse an external value based on the given format options and validate the raw model value based on the given constraints. An implementation of a simple type needs to implement #formatValue, #parseValue and #validateValue. If the raw value, which is the value in model representation, isn't already a JavaScript primitive type, subclasses must override #getModelFormat.


Constructor

Constructor for a new SimpleType.

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

Format options as defined by concrete subclasses

oConstraints? object

Constraints as defined by concrete subclasses


Methods Overview

Method Description
sap.ui.model.SimpleType.extend

Creates a new subclass of class sap.ui.model.SimpleType 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.Type.extend.

formatValue

Formats the given raw value to an output value of the given target type. This happens according to the format options if the target type is string. If vValue is not defined or null, null is returned.

getConstraints

Returns a deep copy of the constraints of this type. The returned constraints can be used to create a new instance of the type with equivalent constraints.

Subclasses may need to override this method.

getFormatOptions

Returns a deep copy of the format options of this type. The returned format options can be used to create a new instance of the type with equivalent format options.

Subclasses may need to override this method.

sap.ui.model.SimpleType.getMetadata

Returns a metadata object for class sap.ui.model.SimpleType.

getModelFormat

Returns an object with format and parse methods. format converts the internal value which has a JavaScript primitive type or is a built-in object such as Date which can be used by a control to the raw value, and parse converts the raw value to the internal value.

You may return an instance of DateFormat or NumberFormat.

The default implementation of the format and parse methods simply returns the given parameter. Subclasses of SimpleType should override this method if the raw value isn't already a JavaScript primitive type. The overwritten method must return an object which has the format and parse methods implemented.

Example:
If the type is related to a JavaScript Date object, but the raw value isn't, this method should return an instance of DateFormat, which is able to convert between the raw value and a JavaScript Date object.

parseValue

Parses an external value of the given source type to the corresponding value in model representation.

validateValue

Validates whether a given raw value meets the defined constraints. This method does nothing if no constraints are defined.

sap.ui.model.SimpleType.extend

Creates a new subclass of class sap.ui.model.SimpleType 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.Type.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 raw value to an output value of the given target type. This happens according to the format options if the target type is string. If vValue is not defined or null, null is returned.

Param Type DefaultValue Description
vValue any

The value to be formatted

sTargetType string

The target type; see Allowed Property Types

getConstraints

Returns a deep copy of the constraints of this type. The returned constraints can be used to create a new instance of the type with equivalent constraints.

Subclasses may need to override this method.

getFormatOptions

Returns a deep copy of the format options of this type. The returned format options can be used to create a new instance of the type with equivalent format options.

Subclasses may need to override this method.

sap.ui.model.SimpleType.getMetadata

Returns a metadata object for class sap.ui.model.SimpleType.

getModelFormat

Returns an object with format and parse methods. format converts the internal value which has a JavaScript primitive type or is a built-in object such as Date which can be used by a control to the raw value, and parse converts the raw value to the internal value.

You may return an instance of DateFormat or NumberFormat.

The default implementation of the format and parse methods simply returns the given parameter. Subclasses of SimpleType should override this method if the raw value isn't already a JavaScript primitive type. The overwritten method must return an object which has the format and parse methods implemented.

Example:
If the type is related to a JavaScript Date object, but the raw value isn't, this method should return an instance of DateFormat, which is able to convert between the raw value and a JavaScript Date object.

parseValue

Parses an external value of the given source type to the corresponding value in model representation.

Param Type DefaultValue Description
vValue any

The value to be parsed

sSourceType string

The type of the given value; see Allowed Property Types

validateValue

Validates whether a given raw value meets the defined constraints. This method does nothing if no constraints are defined.

Param Type DefaultValue Description
vValue any

The value to be validated