Class sap.ui2.srvc.Bag
Defined in: bag.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
sap.ui2.srvc.Bag(oFactory, oAlterEgo, oParentBag, fnChangeListener)
Constructs a new representation (wrapper) of the bag with the given
bag description as loaded from the given factory's page building service.
|
| Method Attributes | Method Name and Description |
|---|---|
|
getId()
Returns this bag's ID.
|
|
|
getProperty(sPropertyName, sDefaultValue)
Returns the property value for the given property name.
|
|
|
Returns an array containing the names of the (non-translatable) properties contained in this
bag.
|
|
|
getText(sTextName)
Returns the translatable text for the given text property name.
|
|
|
Returns an array containing the names of the translatable text properties contained in this
bag.
|
|
|
reset(fnSuccess, fnError)
Discards all modified properties, deletes this bag with all its properties and reloads the
bag via the factory given in the constructor.
|
|
|
resetProperty(sPropertyName)
Deletes the property with the given name, no matter if it is translatable or not.
|
|
|
save(fnSuccess, fnError)
Saves this bag with all modified properties.
|
|
|
setProperty(sPropertyName, sValue)
Sets the value for the given property name.
|
|
|
setText(sTextName, sText)
Sets the translatable text for the given text property name.
|
|
|
toString(bVerbose)
Returns this bag's string representation.
|
- Parameters:
- {sap.ui2.srvc.Factory} oFactory
- the factory
- {object} oAlterEgo
- the bag data including its (optional) properties as loaded via the page building service
- {object} oParentBag Optional
- a bag which is asked for properties not found in this bag
- {function(sap.ui2.srvc.Bag)} fnChangeListener Optional
- (since 1.21) a listener to be called (with this bag as an argument) each time this bag changes due to save or reset; the listener is not called in case a backend request fails completely
- Since:
- 1.3.0
- Since:
- 1.3.0
- Returns:
- {string} this bag's ID
- Parameters:
- {string} sPropertyName
- the property name
- {string} sDefaultValue Optional
- default value used if there is no property with given name
- Since:
- 1.3.0
- Throws:
- Error if
sPropertyNameis a translatable text property name.
- Returns:
- {string} the property value
- Since:
- 1.3.0
- Returns:
- {string[]} array of (non-translatable) property names
- See:
- #getTextNames
sTextName is returned again. As long as a #reset() is running,
"old" texts are returned.
- Parameters:
- {string} sTextName
- the text property name
- Since:
- 1.17.1
- Throws:
- Error if
sTextNameis an ordinary (non-translatable) property name.
- Returns:
- {string} the translatable text
- Since:
- 1.17.1
- Returns:
- {string[]} array of translatable text property names
- See:
- #getPropertyNames
sap.ui2.srvc.PageBuildingService, calling them
scopes), the values from a lower layer will become visible.
This is an asynchronous operation. If the bag is reset successfully, the success handler is called. If there is an error while resetting the bag, all old values are kept and the error handler is called.
- Parameters:
- {function ()} fnSuccess
- no-args success handler
- {function (string|[object])} fnError Optional
- error handler taking an error message and, since version 1.28.6, an optional object containing the complete error information as delivered by the ODataService. See fnFailure parameter of sap.ui2.srvc.ODataWrapper#onError for more details. If fnError is not given, the default error handler from the factory's page building service is called.
- Since:
- 1.3.0
- Throws:
- Error when called while #save() or a previous
reset()is running.
Otherwise, the property value is considered to be undefined until a
#save operation has succeeded. Note how this undefined value is treated
differently by #getProperty and #getText!
BEWARE: This transient undefined value can be wrong due to a number of
reasons, including different layers of storage (like
sap.ui2.srvc.PageBuildingService, calling them scopes) or parent bags
(in case of catalog pages), which cannot be taken properly into account until the next time
a #save operation succeeds!
After a successful #save operation, a deleted property may reappear from a lower layer of storage or from a parent bag. If you need to overwrite such values, use #setProperty instead!
If resetProperty() is called during a running #save, the
property will not be saved immediately. It will only be saved with the next call to
#save.
- Parameters:
- {string} sPropertyName
- the property name (which has to be a string)
- Since:
- 1.17.1
- Throws:
- Error when called while #reset is running.
- Returns:
- {sap.ui2.srvc.Bag} this bag
save().
If save() is called when there is no modified property, the function calls the
success handler asynchronously without any further activity.
- Parameters:
- {function ()} fnSuccess
- no-args success handler. Errors thrown in this function will be reported to the page
building service's default error handler (not to
fnErrorsince the signature does not fit) -
{function (map
|map fnError)} - error handler taking two maps, each mapping individual property names
to error message and complete error information respectively. Since
version 1.28.6, the second parameter is always returned,
but a property name in that object may map to
undefined values in case an error object containing the complete error
information is not available.
For more details about the structure of the error information object see sap.ui2.srvc.ODataWrapper#onError
- Since:
- 1.3.0
- Throws:
- Error when called while #reset() or a previous
save()is running.
setProperty() is called during a running #save(), the
property will not be saved immediately. It will only be saved with the next call to
#save().
- Parameters:
- {string} sPropertyName
- the property name (which has to be a string)
- {string} sValue
- the value (which has to be a string)
- Since:
- 1.3.0
- Throws:
- Error when called while #reset() is running.
- Error when called with a property name which is not of type string or the empty string
- Returns:
- {sap.ui2.srvc.Bag} this bag
reset() and start all over.
Note: You can create or modify translatable text properties only if the session language is
the same as the page's original language (see
sap.ui2.srvc.Page#getOriginalLanguage).
Also note that handling of translatable texts depends on the layer used. In some layers the
original language is important; in others it does not matter. In the latter case the empty
string ("") is returned, which indicates that the user is allowed to edit the
translatable texts in any language.
If setText() is called during a running #save(), the text property will
not be saved immediately. It will only be saved with the next call to #save().
- Parameters:
- {string} sTextName
- the text property name (must not be empty)
- {string} sText
- the translatable text (may be empty)
- Since:
- 1.17.1
- Throws:
- Error when called while #reset() is running or if an ordinary (non-translatable) property with the same name already exists.
- Returns:
- {sap.ui2.srvc.Bag} this bag
- Parameters:
- {boolean} bVerbose Optional, Default: false
- whether to show all properties
- Since:
- 1.3.0
- Returns:
- {string} this bag's string representation