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(mArguments?)Fires event afterInit to attached listeners.
fireAfterRendering(mArguments?)Fires event afterRendering to attached listeners.
fireBeforeExit(mArguments?)Fires event beforeExit to attached listeners.
fireBeforeRendering(mArguments?)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.
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:
{string}sId? id for the new control, generated automatically if no id is given
{object}mSettings? 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.Event}oControlEvent
{sap.ui.base.EventProvider}oControlEvent.getSource
{object}oControlEvent.getParameters
afterRendering(oControlEvent)
Fired when the View has been (re-)rendered and its HTML is present in the DOM.
Parameters:
{sap.ui.base.Event}oControlEvent
{sap.ui.base.EventProvider}oControlEvent.getSource
{object}oControlEvent.getParameters
beforeExit(oControlEvent)
Fired when the view has received the request to destroy itself, but before it has destroyed anything.
Parameters:
{sap.ui.base.Event}oControlEvent
{sap.ui.base.EventProvider}oControlEvent.getSource
{object}oControlEvent.getParameters
beforeRendering(oControlEvent)
Fired before this View is re-rendered. Use to unbind event handlers from HTML elements etc.
Parameters:
{sap.ui.base.Event}oControlEvent
{sap.ui.base.EventProvider}oControlEvent.getSource
{object}oControlEvent.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:
{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.core.mvc.View.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.ui.core.mvc.View.
Returns:
{sap.ui.base.Metadata} Metadata 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 dependant from 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 beeing 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:
{string}sType the type of content to be processed
{string|function}vPreprocessor module path of the preprocessor implementation or a preprocessor function
{string}sViewType type of the calling view, e.g. XML
{boolean}bSyncSupport declares 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.
{boolean}bOnDemand? 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.
{object}mSettings? optional configuration for preprocessor
addContent(oContent): sap.ui.core.mvc.View
Adds some content to the aggregation content.
Parameters:
{sap.ui.core.Control}oContent the content to add; if empty, nothing is inserted
Returns:
{sap.ui.core.mvc.View} Reference 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:
{object}oData? An application-specific payload object that will be passed to the event handler along with the event object when firing the event
{function}fnFunction The function to be called when the event occurs
{object}oListener? Context object to call the event handler with. Defaults to this sap.ui.core.mvc.View itself
Returns:
{sap.ui.core.mvc.View} Reference 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:
{object}oData? An application-specific payload object that will be passed to the event handler along with the event object when firing the event
{function}fnFunction The function to be called when the event occurs
{object}oListener? Context object to call the event handler with. Defaults to this sap.ui.core.mvc.View itself
Returns:
{sap.ui.core.mvc.View} Reference 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:
{object}oData? An application-specific payload object that will be passed to the event handler along with the event object when firing the event
{function}fnFunction The function to be called when the event occurs
{object}oListener? Context object to call the event handler with. Defaults to this sap.ui.core.mvc.View itself
Returns:
{sap.ui.core.mvc.View} Reference 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:
{object}oData? An application-specific payload object that will be passed to the event handler along with the event object when firing the event
{function}fnFunction The function to be called when the event occurs
{object}oListener? Context object to call the event handler with. Defaults to this sap.ui.core.mvc.View itself
Returns:
{sap.ui.core.mvc.View} Reference to this in order to allow method chaining
Returns an element by its ID in the context of the view.
Parameters:
{string}sId View local ID of the element
Returns:
{sap.ui.core.Element} element 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:
{string}sIdSuffix? 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.Element} reference 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:
{string}sId View local ID of the element
Returns:
{string} prefixed id
destroyContent(): sap.ui.core.mvc.View
Destroys all the content in the aggregation content.
Returns:
{sap.ui.core.mvc.View} Reference 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:
{function}fnFunction The function to be called, when the event occurs
{object}oListener Context object on which the given function had to be called
Returns:
{sap.ui.core.mvc.View} Reference 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:
{function}fnFunction The function to be called, when the event occurs
{object}oListener Context object on which the given function had to be called
Returns:
{sap.ui.core.mvc.View} Reference 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:
{function}fnFunction The function to be called, when the event occurs
{object}oListener Context object on which the given function had to be called
Returns:
{sap.ui.core.mvc.View} Reference 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:
{function}fnFunction The function to be called, when the event occurs
{object}oListener Context object on which the given function had to be called
Returns:
{sap.ui.core.mvc.View} Reference to this in order to allow method chaining
fireAfterInit(mArguments?): sap.ui.core.mvc.View
Fires event afterInit to attached listeners.
Parameters:
{Map}mArguments? The arguments to pass along with the event
Returns:
{sap.ui.core.mvc.View} Reference to this in order to allow method chaining
fireAfterRendering(mArguments?): sap.ui.core.mvc.View
Fires event afterRendering to attached listeners.
Parameters:
{Map}mArguments? The arguments to pass along with the event
Returns:
{sap.ui.core.mvc.View} Reference to this in order to allow method chaining
fireBeforeExit(mArguments?): sap.ui.core.mvc.View
Fires event beforeExit to attached listeners.
Parameters:
{Map}mArguments? The arguments to pass along with the event
Returns:
{sap.ui.core.mvc.View} Reference to this in order to allow method chaining
fireBeforeRendering(mArguments?): sap.ui.core.mvc.View
Fires event beforeRendering to attached listeners.
Parameters:
{Map}mArguments? The arguments to pass along with the event
Returns:
{sap.ui.core.mvc.View} Reference 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:
{object} Controller 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:
{string} the 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:
{boolean} Value of property displayBlock
getHeight(): sap.ui.core.CSSSize
Gets current value of property height.

The height

Returns:
{sap.ui.core.CSSSize} Value of property height
getViewData(): object
Returns user specific data object
Returns:
{object} viewData
getViewName(): string
Gets current value of property viewName.

Name of the View

Returns:
{string} Value of property viewName
getWidth(): sap.ui.core.CSSSize
Gets current value of property width.

The width

Default value is 100%.

Returns:
{sap.ui.core.CSSSize} Value of property width
hasPreprocessor(sType): boolean
Checks if any preprocessors are active for the specified type
Parameters:
{string}sType Type of the preprocessor, e.g. "raw", "xml" or "controls"
Returns:
{boolean}true 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.Control}oContent The content whose index is looked for
Returns:
{int} The 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.Control}oContent the content to insert; if empty, nothing is inserted
{int}iIndex the 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.View} Reference 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.

Since:
1.30
Returns:
{Promise} resolves with the view instance, fulfilled when completely initialized
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.Control}vContent The contentto remove or its index or id
Returns:
{sap.ui.core.Control} The removed content or null
runPreprocessor(sType, vSource, bSync?): Promise|object|string|element
Executes preprocessors for a type of source
Parameters:
{string}sType the type of preprocessor, e.g. "raw", "xml" or "controls"
{object|string|Element}vSource the view source as a JSON object, a raw text, an XML document element or a Promise resolving with those
{boolean}bSync? describes the view execution, true if sync
Returns:
{Promise|object|string|element} a 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:
{boolean}bDisplayBlock New value for property displayBlock
Returns:
{sap.ui.core.mvc.View} Reference 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.CSSSize}sHeight New value for property height
Returns:
{sap.ui.core.mvc.View} Reference 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:
{string}sViewName New value for property viewName
Returns:
{sap.ui.core.mvc.View} Reference 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.CSSSize}sWidth New value for property width
Returns:
{sap.ui.core.mvc.View} Reference to this in order to allow method chaining