docs

Message Handling

Recommended guidelines for message handling.

We recommend to invest care and energy in good message content:


For showing messages to the user that are related to the currrent page, you have several possible controls. Each of these offers a different type of interaction from the user. Choose the control that fits best in you interaction pattern.


Message Dialog

Example:

	// load MessageBox asynchronously
	sap.ui.require(['sap/m/MessageBox'], function(MessageBox) {
	
		// and display message
		MessageBox.show(
			"This message should appear in the message box.", {
				icon: MessageBox.Icon.INFORMATION,
				title: "My message box title",
				actions: [MessageBox.Action.YES, MessageBox.Action.NO],
				onClose: function(oAction) { / * do something * / }
			}
		);
	});

Message Toast

Example:

	// add MessageToast as import
	sap.ui.define([..., 'sap/m/MessageToast', ...], function(..., MessageToast, ...) {

		...
		// show toast when needed
		MessageToast.show("Item deleted");
		...

	});

MessageStrip

MessageStrip enables the embedding of short application-related messages in the application. There are four types of messages and each is color-coded and has an icon corresponding to its type: Information, Success, Warning and Error.

Example:

	// add MessageStrip and MessageType as imports
	sap.ui.define([..., 'sap/m/MessageStrip', 'sap/ui/core/library', ...], function(..., MessageToast, coreLibrary, ...) {
	
	...
		var MessageType = coreLibrary.MessageType;
		
		var msg = new MessageStrip({
			id: "importantMessage",
			text: "This is a sample text",
			type: MessageType.Error,
			showIcon: true,
			showCloseButton: true
		});
		
	...
	});

The MessageStrip is useful when you want to display short notices, for example of finished background tasks, that do not require further user interaction.


MessagePopover

MessagePopover shows a summarized list of different types of messages (errors, warnings, success and information). It provides a handy and systemized way to navigate and explore details for every message. You can find more information on MessagePopover here.


MessageView

MessageView shows the same type of summarized messages list as the MessagePopover. The main difference between the controls is that the MessageView can be embedded in any suitable control (for example a Dialog). This allows the message summary to be shown in any part of the application. As of version 1.46, MessagePopover has been refactored to automatically instantiate and use a MessageView for its content. All other controls need to instantiate it themselves. Here is a sample for a MessageView in a Dialog:

...
	sap.ui.require(['sap/m/Dialog', 'sap/m/MessageView', 'sap/m/Bar', 'sap/m/Button', 'sap/m/Text'], 
		function(Dialog, MessageView, Bar, Button, Text) {
	
			// create message view 
			var oMessageView = new MessageView({
				showDetailsPageHeader: false,
				itemSelect: function () {
					that._oBackButton.setVisible(true);
				},
				items: {
					path: "/",
					template: oMessageTemplate
				}
			});

			...

			var oDialog = new Dialog({
				title: "Messages",
				resizable: true,
				content: oMessageView,
				state: 'Error',
				beginButton: new Button({
					press: function () {
						oDialog.close();
					},
					text: "Close"
				}),
				customHeader: new Bar({
					contentMiddle: [
						new Text({ text: "Error"})
					],
					contentLeft: [
						oBackButton
					]
				}),
				contentHeight: "300px",
				contentWidth: "500px",
				verticalScrolling: false
			});
	
			oDialog.open();
			...
		
		}
	);
...

There is no dedicated UI control available in sap.m designed to show messages related to a particular element on a page. We recommend to use the sap.ui.core.HTML control to show these error messages ‘somewhere close to the input’ or use some kind of overlay. Consider that the user will have the on screen keyboard open which might hide messages. Putting the message above an input field could help.

You can set the ValueState of the sap.m.Input control to Error to indicate that the content is not correct.


Multiple Messages

OpenUI5 Mobile does not support multiple messages at the same time. Mobile Designs recommend to be ‘more sparse’ with messages, that is, only show one message at a time. This can also be achieved by combining and reducing multiple messages.

Related Information

Message Popover