Class sap.ui.core.mvc.ViewModule: sap/ui/core/mvc/View

extends Control
known direct subclasses: HTMLView, JSONView, JSView, TemplateView, XMLView

A base class for Views.

Introduces the relationship to a Controller, some basic visual appearance settings like width and height and provides lifecycle events.

Namespaces & Classes
PreprocessorInterface for Preprocessor implementations that can be hooked in the view life cycle.
Constructor Summary
new sap.ui.core.mvc.View(sId?, mSettings?)Constructor for a new View.
Event Summary
afterInit(oControlEvent)Fired when the View has parsed the UI description and instantiated the contained controls (/control tree).
afterRendering(oControlEvent)Fired when the View has been (re-)rendered and its HTML is present in the DOM.
beforeExit(oControlEvent)Fired when the view has received the request to destroy itself, but before it has destroyed anything.
beforeRendering(oControlEvent)Fired before this View is re-rendered.
Events borrowed from class sap.ui.core.Control
Method Summary
sap.ui.core.mvc.View.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.ui.core.mvc.View with name sClassName and enriches it with the information contained in oClassInfo.
sap.ui.core.mvc.View.getMetadata()Returns a metadata object for class sap.ui.core.mvc.View.
sap.ui.core.mvc.View.registerPreprocessor(sType, vPreprocessor, sViewType, bSyncSupport, bOnDemand?, mSettings?)Register a preprocessor for all views of a specific type.
addContent(oContent)Adds some content to the aggregation content.
attachAfterInit(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the afterInit event of this sap.ui.core.mvc.View.
attachAfterRendering(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the afterRendering event of this sap.ui.core.mvc.View.
attachBeforeExit(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the beforeExit event of this sap.ui.core.mvc.View.
attachBeforeRendering(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the beforeRendering event of this sap.ui.core.mvc.View.
byId(sId)Returns an element by its ID in the context of the view.
clone(sIdSuffix?, aLocalIds?)Override clone method to avoid conflict between generic cloning of content and content creation as defined by the UI5 Model View Controller lifecycle.
createId(sId)Convert the given view local element ID to a globally unique ID by prefixing it with the view ID.
destroyContent()Destroys all the content in the aggregation content.
detachAfterInit(fnFunction, oListener)Detaches event handler fnFunction from the afterInit event of this sap.ui.core.mvc.View.
detachAfterRendering(fnFunction, oListener)Detaches event handler fnFunction from the afterRendering event of this sap.ui.core.mvc.View.
detachBeforeExit(fnFunction, oListener)Detaches event handler fnFunction from the beforeExit event of this sap.ui.core.mvc.View.
detachBeforeRendering(fnFunction, oListener)Detaches event handler fnFunction from the beforeRendering event of this sap.ui.core.mvc.View.
fireAfterInit(mParameters?)Fires event afterInit to attached listeners.
fireAfterRendering(mParameters?)Fires event afterRendering to attached listeners.
fireBeforeExit(mParameters?)Fires event beforeExit to attached listeners.
fireBeforeRendering(mParameters?)Fires event beforeRendering to attached listeners.
getContent()Gets content of aggregation content.
getController()Returns the view's Controller instance or null for a controller-less View.
getControllerName()An (optional) method to be implemented by Views.
getDisplayBlock()Gets current value of property displayBlock.
getHeight()Gets current value of property height.
getLocalId(sId)Returns the local ID of an element by removing the view ID prefix or null if the ID does not contain a prefix.
getPreprocessorInfo(bSync)Returns the info object which is also passed to the preprocessors
getViewData()Returns user specific data object
getViewName()Gets current value of property viewName.
getWidth()Gets current value of property width.
hasPreprocessor(sType)Checks if any preprocessors are active for the specified type
indexOfContent(oContent)Checks for the provided sap.ui.core.Control in the aggregation content.
insertContent(oContent, iIndex)Inserts a content into the aggregation content.
loaded()Creates a Promise representing the state of the view initialization.
removeAllContent()Removes all the controls from the aggregation content.
removeContent(vContent)Removes a content from the aggregation content.
runPreprocessor(sType, vSource, bSync?)Executes preprocessors for a type of source
setDisplayBlock(bDisplayBlock)Sets a new value for property displayBlock.
setHeight(sHeight)Sets a new value for property height.
setViewName(sViewName)Sets a new value for property viewName.
setWidth(sWidth)Sets a new value for property width.
Constructor Detail
new sap.ui.core.mvc.View(sId?, mSettings?)

Constructor for a new View.

Accepts an object literal mSettings that defines initial property values, aggregated and associated objects as well as event handlers. See sap.ui.base.ManagedObject for a general description of the syntax of the settings object.

The supported settings are:

  • Properties

  • Aggregations

  • Events

    • afterInit : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]
    • beforeExit : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]
    • afterRendering : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]
    • beforeRendering : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]

In addition, all settings applicable to the base type sap.ui.core.Control can be used as well.

Parameters:
stringsId?id for the new control, generated automatically if no id is given
objectmSettings?initial settings for the new control
Event Detail
afterInit(oControlEvent)
Fired when the View has parsed the UI description and instantiated the contained controls (/control tree).
Parameters:
sap.ui.base.EventoControlEvent
sap.ui.base.EventProvideroControlEvent.getSource
objectoControlEvent.getParameters
afterRendering(oControlEvent)
Fired when the View has been (re-)rendered and its HTML is present in the DOM.
Parameters:
sap.ui.base.EventoControlEvent
sap.ui.base.EventProvideroControlEvent.getSource
objectoControlEvent.getParameters
beforeExit(oControlEvent)
Fired when the view has received the request to destroy itself, but before it has destroyed anything.
Parameters:
sap.ui.base.EventoControlEvent
sap.ui.base.EventProvideroControlEvent.getSource
objectoControlEvent.getParameters
beforeRendering(oControlEvent)
Fired before this View is re-rendered. Use to unbind event handlers from HTML elements etc.
Parameters:
sap.ui.base.EventoControlEvent
sap.ui.base.EventProvideroControlEvent.getSource
objectoControlEvent.getParameters
Method Detail
sap.ui.core.mvc.View.extend(sClassName, oClassInfo?, FNMetaImpl?): function

Creates a new subclass of class sap.ui.core.mvc.View 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.core.Control.extend.

Parameters:
stringsClassNameName of the class being created
objectoClassInfo?Object literal with information about the class
functionFNMetaImpl?Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
functionCreated class / constructor function
sap.ui.core.mvc.View.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.ui.core.mvc.View.
Returns:
sap.ui.base.MetadataMetadata object describing this class
sap.ui.core.mvc.View.registerPreprocessor(sType, vPreprocessor, sViewType, bSyncSupport, bOnDemand?, mSettings?)

Register a preprocessor for all views of a specific type.

The preprocessor can be registered for several stages of view initialization, which are dependent on the view type, e.g. "raw", "xml" or already initialized "controls". If there is a preprocessor passed to or activated at the view instance already, that one is used. When several preprocessors are registered for one hook, it has to be made sure that they do not conflict when being processed serially.

It can be either a module name as string of an implementation of sap.ui.core.mvc.View.Preprocessor or a function with a signature according to sap.ui.core.mvc.View.Preprocessor.process.

Note: Preprocessors only work in async views and will be ignored when the view is instantiated in sync mode by default, as this could have unexpected side effects. You may override this behaviour by setting the bSyncSupport flag to true.

Parameters:
stringsTypethe type of content to be processed
string|functionvPreprocessormodule path of the preprocessor implementation or a preprocessor function
stringsViewTypetype of the calling view, e.g. XML
booleanbSyncSupportdeclares if the vPreprocessor ensures safe sync processing. This means the preprocessor will be executed also for sync views. Please be aware that any kind of async processing (like Promises, XHR, etc) may break the view initialization and lead to unexpected results.
booleanbOnDemand?on-demand preprocessor which enables developers to quickly activate the preprocessor for a view, by setting preprocessors : { xml }, for example. This should be false except for very special cases. There can only be one on-demand preprocessor per content type.
objectmSettings?optional configuration for preprocessor
addContent(oContent): sap.ui.core.mvc.View
Adds some content to the aggregation content.
Parameters:
sap.ui.core.ControloContentthe content to add; if empty, nothing is inserted
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
attachAfterInit(oData?, fnFunction, oListener?): sap.ui.core.mvc.View

Attaches event handler fnFunction to the afterInit event of this sap.ui.core.mvc.View.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.mvc.View itself.

Fired when the View has parsed the UI description and instantiated the contained controls (/control tree).

Parameters:
objectoData?An application-specific payload object that will be passed to the event handler along with the event object when firing the event
functionfnFunctionThe function to be called when the event occurs
objectoListener?Context object to call the event handler with. Defaults to this sap.ui.core.mvc.View itself
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
attachAfterRendering(oData?, fnFunction, oListener?): sap.ui.core.mvc.View

Attaches event handler fnFunction to the afterRendering event of this sap.ui.core.mvc.View.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.mvc.View itself.

Fired when the View has been (re-)rendered and its HTML is present in the DOM.

Parameters:
objectoData?An application-specific payload object that will be passed to the event handler along with the event object when firing the event
functionfnFunctionThe function to be called when the event occurs
objectoListener?Context object to call the event handler with. Defaults to this sap.ui.core.mvc.View itself
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
attachBeforeExit(oData?, fnFunction, oListener?): sap.ui.core.mvc.View

Attaches event handler fnFunction to the beforeExit event of this sap.ui.core.mvc.View.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.mvc.View itself.

Fired when the view has received the request to destroy itself, but before it has destroyed anything.

Parameters:
objectoData?An application-specific payload object that will be passed to the event handler along with the event object when firing the event
functionfnFunctionThe function to be called when the event occurs
objectoListener?Context object to call the event handler with. Defaults to this sap.ui.core.mvc.View itself
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
attachBeforeRendering(oData?, fnFunction, oListener?): sap.ui.core.mvc.View

Attaches event handler fnFunction to the beforeRendering event of this sap.ui.core.mvc.View.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.mvc.View itself.

Fired before this View is re-rendered. Use to unbind event handlers from HTML elements etc.

Parameters:
objectoData?An application-specific payload object that will be passed to the event handler along with the event object when firing the event
functionfnFunctionThe function to be called when the event occurs
objectoListener?Context object to call the event handler with. Defaults to this sap.ui.core.mvc.View itself
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
Returns an element by its ID in the context of the view.
Parameters:
stringsIdView local ID of the element
Returns:
sap.ui.core.Elementelement by its ID or undefined
clone(sIdSuffix?, aLocalIds?): sap.ui.core.Element

Override clone method to avoid conflict between generic cloning of content and content creation as defined by the UI5 Model View Controller lifecycle.

For more details see the development guide section about Model View Controller in UI5.

Parameters:
stringsIdSuffix?a suffix to be appended to the cloned element id
string[]aLocalIds?an array of local IDs within the cloned hierarchy (internally used)
Returns:
sap.ui.core.Elementreference to the newly created clone
createId(sId): string
Convert the given view local element ID to a globally unique ID by prefixing it with the view ID.
Parameters:
stringsIdView local ID of the element
Returns:
stringprefixed id
destroyContent(): sap.ui.core.mvc.View
Destroys all the content in the aggregation content.
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
detachAfterInit(fnFunction, oListener): sap.ui.core.mvc.View

Detaches event handler fnFunction from the afterInit event of this sap.ui.core.mvc.View.

The passed function and listener object must match the ones used for event registration.

Parameters:
functionfnFunctionThe function to be called, when the event occurs
objectoListenerContext object on which the given function had to be called
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
detachAfterRendering(fnFunction, oListener): sap.ui.core.mvc.View

Detaches event handler fnFunction from the afterRendering event of this sap.ui.core.mvc.View.

The passed function and listener object must match the ones used for event registration.

Parameters:
functionfnFunctionThe function to be called, when the event occurs
objectoListenerContext object on which the given function had to be called
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
detachBeforeExit(fnFunction, oListener): sap.ui.core.mvc.View

Detaches event handler fnFunction from the beforeExit event of this sap.ui.core.mvc.View.

The passed function and listener object must match the ones used for event registration.

Parameters:
functionfnFunctionThe function to be called, when the event occurs
objectoListenerContext object on which the given function had to be called
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
detachBeforeRendering(fnFunction, oListener): sap.ui.core.mvc.View

Detaches event handler fnFunction from the beforeRendering event of this sap.ui.core.mvc.View.

The passed function and listener object must match the ones used for event registration.

Parameters:
functionfnFunctionThe function to be called, when the event occurs
objectoListenerContext object on which the given function had to be called
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
fireAfterInit(mParameters?): sap.ui.core.mvc.View
Fires event afterInit to attached listeners.
Parameters:
objectmParameters?Parameters to pass along with the event
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
fireAfterRendering(mParameters?): sap.ui.core.mvc.View
Fires event afterRendering to attached listeners.
Parameters:
objectmParameters?Parameters to pass along with the event
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
fireBeforeExit(mParameters?): sap.ui.core.mvc.View
Fires event beforeExit to attached listeners.
Parameters:
objectmParameters?Parameters to pass along with the event
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
fireBeforeRendering(mParameters?): sap.ui.core.mvc.View
Fires event beforeRendering to attached listeners.
Parameters:
objectmParameters?Parameters to pass along with the event
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
getContent(): sap.ui.core.Control[]

Gets content of aggregation content.

Child Controls of the view

Returns:
sap.ui.core.Control[]
getController(): object
Returns the view's Controller instance or null for a controller-less View.
Returns:
objectController of this view.
getControllerName(): string
An (optional) method to be implemented by Views. When no controller instance is given at View instantiation time AND this method exists and returns the (package and class) name of a controller, the View tries to load and instantiate the controller and to connect it to itself.
Returns:
stringthe name of the controller
getDisplayBlock(): boolean

Gets current value of property displayBlock.

Whether the CSS display should be set to "block". Set this to "true" if the default display "inline-block" causes a vertical scrollbar with Views that are set to 100% height. Do not set this to "true" if you want to display other content in the same HTML parent on either side of the View (setting to "true" may push that other content to the next/previous line).

Default value is false.

Returns:
booleanValue of property displayBlock
getHeight(): sap.ui.core.CSSSize

Gets current value of property height.

The height

Returns:
sap.ui.core.CSSSizeValue of property height
getLocalId(sId): string
Returns the local ID of an element by removing the view ID prefix or null if the ID does not contain a prefix.
Parameters:
stringsIdPrefixed ID
Returns:
stringID without prefix or null
Since:
1.39.0
getPreprocessorInfo(bSync): object
Returns the info object which is also passed to the preprocessors
Parameters:
booleanbSyncDescribes the view execution, true if sync
Returns:
objectInfo object for the view
See:
sap.ui.core.mvc.View.Preprocessor.process
getViewData(): object
Returns user specific data object
Returns:
objectviewData
getViewName(): string

Gets current value of property viewName.

Name of the View

Returns:
stringValue of property viewName
getWidth(): sap.ui.core.CSSSize

Gets current value of property width.

The width

Default value is 100%.

Returns:
sap.ui.core.CSSSizeValue of property width
hasPreprocessor(sType): boolean
Checks if any preprocessors are active for the specified type
Parameters:
stringsTypeType of the preprocessor, e.g. "raw", "xml" or "controls"
Returns:
booleantrue if a preprocessor is active
indexOfContent(oContent): int
Checks for the provided sap.ui.core.Control in the aggregation content. and returns its index if found or -1 otherwise.
Parameters:
sap.ui.core.ControloContentThe content whose index is looked for
Returns:
intThe index of the provided control in the aggregation if found, or -1 otherwise
insertContent(oContent, iIndex): sap.ui.core.mvc.View
Inserts a content into the aggregation content.
Parameters:
sap.ui.core.ControloContentthe content to insert; if empty, nothing is inserted
intiIndexthe 0-based index the content should be inserted at; for a negative value of iIndex, the content is inserted at position 0; for a value greater than the current size of the aggregation, the content is inserted at the last position
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
loaded(): Promise

Creates a Promise representing the state of the view initialization.

For views that are loading asynchronously (by setting async=true) this Promise is created by view initialization. Synchronously loading views get wrapped in an immediately resolving Promise.

Returns:
Promiseresolves with the complete view instance, reject with any thrown error
Since:
1.30
removeAllContent(): sap.ui.core.Control[]

Removes all the controls from the aggregation content.

Additionally, it unregisters them from the hosting UIArea.

Returns:
sap.ui.core.Control[]An array of the removed elements (might be empty)
removeContent(vContent): sap.ui.core.Control
Removes a content from the aggregation content.
Parameters:
int|string|sap.ui.core.ControlvContentThe content to remove or its index or id
Returns:
sap.ui.core.ControlThe removed content or null
runPreprocessor(sType, vSource, bSync?): Promise|object|string|Element
Executes preprocessors for a type of source
Parameters:
stringsTypethe type of preprocessor, e.g. "raw", "xml" or "controls"
object|string|ElementvSourcethe view source as a JSON object, a raw text, an XML document element or a Promise resolving with those
booleanbSync?describes the view execution, true if sync
Returns:
Promise|object|string|Elementa promise resolving with the processed source or an error | the source when bSync=true
setDisplayBlock(bDisplayBlock): sap.ui.core.mvc.View

Sets a new value for property displayBlock.

Whether the CSS display should be set to "block". Set this to "true" if the default display "inline-block" causes a vertical scrollbar with Views that are set to 100% height. Do not set this to "true" if you want to display other content in the same HTML parent on either side of the View (setting to "true" may push that other content to the next/previous line).

When called with a value of null or undefined, the default value of the property will be restored.

Default value is false.

Parameters:
booleanbDisplayBlockNew value for property displayBlock
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
setHeight(sHeight): sap.ui.core.mvc.View

Sets a new value for property height.

The height

When called with a value of null or undefined, the default value of the property will be restored.

Parameters:
sap.ui.core.CSSSizesHeightNew value for property height
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
setViewName(sViewName): sap.ui.core.mvc.View

Sets a new value for property viewName.

Name of the View

When called with a value of null or undefined, the default value of the property will be restored.

Parameters:
stringsViewNameNew value for property viewName
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining
setWidth(sWidth): sap.ui.core.mvc.View

Sets a new value for property width.

The width

When called with a value of null or undefined, the default value of the property will be restored.

Default value is 100%.

Parameters:
sap.ui.core.CSSSizesWidthNew value for property width
Returns:
sap.ui.core.mvc.ViewReference to this in order to allow method chaining