Class sap.ui.model.DataStateModule: sap/ui/model/DataState

extends Object
known direct subclasses: CompositeDataState

Provides and update the status data of a binding. Depending on the models state and controls state changes, the data state is used to propagated changes to a control. The control can react on these changes by implementing the refreshDataState method for the control. Here the the data state object is passed as a parameter.

Using the getChanges method the control can determine the changed properties and their old and new value.

    //sample implementation to handle message changes
    myControl.prototype.refreshDataState = function(oDataState) {
       var aMessages = oDataState.getChanges().messages;
       if (aMessages) {
           for (var i = 0; i < aMessages.length; i++) {
               console.log(aMessages.message);
           }
       }
    }

    //sample implementation to handle laundering state
    myControl.prototype.refreshDataState = function(oDataState) {
       var bLaundering = oDataState.getChanges().laundering || false;
       this.setBusy(bLaundering);
    }

    //sample implementation to handle dirty state
    myControl.prototype.refreshDataState = function(oDataState) {
       if (oDataState.isDirty()) console.log("Control " + this.getId() + " is now dirty");
    }

Using the getProperty method the control can read the properties of the data state. The properties are

  • value The value formatted by the formatter of the binding
  • originalValue The original value of the model formatted by the formatter of the binding
  • invalidValue The control value that was tried to be applied to the model but was rejected by a type validation
  • modelMessages The messages that were applied to the binding by the sap.ui.model.MessageModel
  • controlMessages The messages that were applied due to type validation errors
  • messages All messages of the data state
  • dirty true if the value was not yet confirmed by the server

Constructor Summary
Method Summary
sap.ui.model.DataState.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.ui.model.DataState with name sClassName and enriches it with the information contained in oClassInfo.
sap.ui.model.DataState.getMetadata()Returns a metadata object for class sap.ui.model.DataState.
changed(bNewState?)Returns or sets whether the data state is changed.
getChanges()Returns the changes of the data state in a map that the control can use in the refreshDataState method.
getControlMessages()Returns the array of state messages of the control or undefined.
getInvalidValue()Returns the dirty value of a binding that was rejected by a type validation.
getMessages()Returns the array of all state messages or null.
getModelMessages()Returns the array of state messages of the model or undefined
getOriginalValue()Returns the formatted original value of the data.
getValue()Returns the formatted value of the data state.
isControlDirty()Returns whether the data state is dirty in the UI control.
isDirty()Returns whether the data state is dirty.
isLaundering()Returns whether the data state is in laundering.
setControlMessages(the)Sets an array of control state messages.
setInvalidValue(vInvalidValue)Sets the dirty value that was rejected by the type validation.
setLaundering(bLaundering)Sets the laundering state of the data state.
setModelMessages(the)Sets an array of model state messages.
setOriginalValue(vOriginalValue)Sets the formatted original value of the data.
setValue(vValue)Sets the formatted value of the data state,
Methods borrowed from class sap.ui.base.Object
Constructor Detail
new sap.ui.model.DataState()
Method Detail
sap.ui.model.DataState.extend(sClassName, oClassInfo?, FNMetaImpl?): function
Creates a new subclass of class sap.ui.model.DataState 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.base.Object.extend.

Parameters:
{string}sClassName Name of the class being created
{object}oClassInfo? Object literal with information about the class
{function}FNMetaImpl? Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
{function} Created class / constructor function
sap.ui.model.DataState.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.ui.model.DataState.
Returns:
{sap.ui.base.Metadata} Metadata object describing this class
changed(bNewState?): boolean
Returns or sets whether the data state is changed. As long as changed was not set to false the data state is dirty and the corresponding binding will fire data state change events.
Parameters:
{boolean}bNewState? the optional new state
Returns:
{boolean} whether the data state was changed.
getChanges(): map
Returns the changes of the data state in a map that the control can use in the refreshDataState method. The changed property's name is the key in the map. Each element in the map contains an object of below structure.
   {
       oldValue : The old value of the property,
       value    : The new value of the property
   }
The map only contains the changed properties.
Returns:
{map} the changed of the data state
getControlMessages(): sap.ui.core.Message[]
Returns the array of state messages of the control or undefined.
Returns:
{sap.ui.core.Message[]} the array of messages of the control or null if no {link:sap.ui.core.messages.ModelManager ModelManager} is used.
getInvalidValue(): any
Returns the dirty value of a binding that was rejected by a type validation. This value was of an incorrect type and could not be applied to the model. If the value was not rejected it will return null. In this case the current model value can be accessed using the getValue method.
Returns:
{any} the value that was rejected or null
getMessages(): sap.ui.core.Message[]
Returns the array of all state messages or null. This combines the model and control messages.
Returns:
{sap.ui.core.Message[]} the array of all messages or null if no {link:sap.ui.core.messages.ModelManager ModelManager} is used.
getModelMessages(): sap.ui.core.Message[]
Returns the array of state messages of the model or undefined
Returns:
{sap.ui.core.Message[]} the array of messages of the model or null if no {link:sap.ui.core.messages.ModelManager ModelManager} is used.
getOriginalValue(): any
Returns the formatted original value of the data. The original value is the last confirmed value.
Returns:
{any} the original confirmed value of the server
getValue(): any
Returns the formatted value of the data state.
Returns:
{any} The value of the data.
isControlDirty(): boolean
Returns whether the data state is dirty in the UI control. A data state is dirty in the UI control if the entered value did not yet pass the type validation.
Returns:
{boolean} true if the data state is dirty
isDirty(): boolean
Returns whether the data state is dirty. A data state is dirty if the value was changed but is not yet confirmed by a server or the entered value did not yet pass the type validation.
Returns:
{boolean} true if the data state is dirty
isLaundering(): boolean
Returns whether the data state is in laundering. If data is send to the server the data state becomes laundering until the data was accepted or rejected.
Returns:
{boolean} true if the data is laundering
setControlMessages(the): sap.ui.model.DataState
Sets an array of control state messages.
Parameters:
{sap.ui.core.Message[]}the control messages
Returns:
{sap.ui.model.DataState}this to allow method chaining
setInvalidValue(vInvalidValue): sap.ui.model.DataState
Sets the dirty value that was rejected by the type validation.
Parameters:
{any}vInvalidValue the value that was rejected by the type validation or null if the value was valid
Returns:
{sap.ui.model.DataState}this to allow method chaining
setLaundering(bLaundering): sap.ui.model.DataState
Sets the laundering state of the data state.
Parameters:
{boolean}bLaundering true if the state is laundering
Returns:
{sap.ui.model.DataState}this to allow method chaining
setModelMessages(the): sap.ui.model.DataState
Sets an array of model state messages.
Parameters:
{array}the model messages for this data state.
Returns:
{sap.ui.model.DataState}this to allow method chaining
setOriginalValue(vOriginalValue): sap.ui.model.DataState
Sets the formatted original value of the data.
Parameters:
{boolean}vOriginalValue the original value
Returns:
{sap.ui.model.DataState}this to allow method chaining
setValue(vValue): sap.ui.model.DataState
Sets the formatted value of the data state,
Parameters:
{any}vValue the value
Returns:
{sap.ui.model.DataState}this to allow method chaining