Message Dialog
Creating a dialog for showing UI messages. The possible messages types are: 'None', 'Success', 'Warning' and 'Error'.
Z2UI5_CL_SMPC_APP_273
Controls
sap.m
UI5 1.71
The facts
- Repository
- abap2UI5/samples-controls
- Class
Z2UI5_CL_SMPC_APP_273- Source file
z2ui5_cl_smpc_app_273.clas.abap↗- Library
- sap.m
- UI5 entity
sap.m.Dialog- Demo kit sample
sap.m.sample.DialogMessage- SAP's own sample
- running at sdk.openui5.org ↗
- Minimum UI5
- 1.71 — the floor abap2UI5 holds its samples to
- In the playground
- runs in the browser, with no system and nothing installed
Keywords: dialog, sap.m, dialogmessage, verticallayout, button, text
Controls it builds
- sap.m.Button
- sap.m.Dialog
- sap.m.Text
- sap.ui.core.FragmentDefinition
- sap.ui.core.mvc.View
- sap.ui.layout.VerticalLayout
Read out of the builder chain by the abap2UI5 linter, not from the category this sample is filed under — which is what makes “which samples build one of these” a question the catalogue can answer at all.
Libraries
Run it here
The sample running, in this page — the app on its own, with no editor over it.
Switch to Playground with this code
Nothing is installed and nothing is sent anywhere: the ABAP is compiled to JavaScript in this browser and runs against abap2UI5 itself.
The ABAP
z2ui5_cl_smpc_app_273.clas.abap — 165 lines
Click a number to link to a line — shift-click for a range.
Read it on GitHub ↗
" @keywords dialog sap.m dialogmessage verticallayout button text
" @summary Creating a dialog for showing UI messages. The possible messages types are: 'None', 'Success', 'Warning' and 'Error'.
CLASS z2ui5_cl_smpc_app_273 DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.
METHODS view_display.
METHODS model_init.
METHODS on_event.
METHODS popup_message_display
IMPORTING
title TYPE string
state TYPE string
text TYPE string.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_smpc_app_273 IMPLEMENTATION.
METHOD z2ui5_if_app~main.
me->client = client.
IF client->check_on_init( ).
model_init( ).
view_display( ).
ELSEIF client->check_on_navigated( ).
view_display( ).
ELSEIF client->check_on_event( ).
on_event( ).
ENDIF.
ENDMETHOD.
METHOD view_display.
DATA(view) = z2ui5_cl_ui5_view_builder=>factory( ).
view->ele( n = `View` ns = `mvc`
)->a( n = `xmlns` v = `sap.m`
)->a( n = `xmlns:l` v = `sap.ui.layout`
)->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
)->ele( n = `VerticalLayout` ns = `l`
)->a( n = `class` v = `sapUiContentPadding`
)->a( n = `width` v = `100%`
)->tag( `Button`
)->a( n = `text` v = `Message Dialog`
)->a( n = `width` v = `230px`
)->a( n = `press` v = client->_event( `DEFAULT_DIALOG` )
)->a( n = `class` v = `sapUiSmallMarginBottom`
)->tag( `Button`
)->a( n = `text` v = `Message Dialog (Success)`
)->a( n = `width` v = `230px`
)->a( n = `press` v = client->_event( `SUCCESS_DIALOG` )
)->a( n = `class` v = `sapUiSmallMarginBottom`
)->tag( `Button`
)->a( n = `text` v = `Message Dialog (Warning)`
)->a( n = `width` v = `230px`
)->a( n = `press` v = client->_event( `WARNING_DIALOG` )
)->a( n = `class` v = `sapUiSmallMarginBottom`
)->tag( `Button`
)->a( n = `text` v = `Message Dialog (Error)`
)->a( n = `width` v = `230px`
)->a( n = `press` v = client->_event( `ERROR_DIALOG` )
)->a( n = `class` v = `sapUiSmallMarginBottom`
)->tag( `Button`
)->a( n = `text` v = `Message Dialog (Information)`
)->a( n = `width` v = `230px`
)->a( n = `press` v = client->_event( `INFORMATION_DIALOG` )
)->a( n = `class` v = `sapUiSmallMarginBottom` ).
client->view_display( view->stringify( ) ).
ENDMETHOD.
METHOD on_event.
" the five controller-built Dialogs, one per press handler: same type,
" title, state and content text, and the same single Emphasized OK button
CASE client->get_event( ).
WHEN `DEFAULT_DIALOG`.
popup_message_display( title = `Default Message`
state = ``
text = `Build enterprise-ready web applications, responsive to all devices and ` &&
`running on the browser of your choice. That's OpenUI5.` ).
WHEN `SUCCESS_DIALOG`.
popup_message_display( title = `Success`
state = `Success`
text = `One of the keys to success is creating realistic goals that can be ` &&
`achieved in a reasonable amount of time.` ).
WHEN `WARNING_DIALOG`.
popup_message_display( title = `Warning`
state = `Warning`
text = `Ruling the world is a time-consuming task. You will not have a lot of ` &&
`spare time.` ).
WHEN `ERROR_DIALOG`.
popup_message_display( title = `Error`
state = `Error`
text = `The only error you can make is to not even try.` ).
WHEN `INFORMATION_DIALOG`.
popup_message_display( title = `Information`
state = `Information`
text = `Dialog with value state Information.` ).
ENDCASE.
ENDMETHOD.
METHOD popup_message_display.
DATA(popup) = z2ui5_cl_ui5_view_builder=>factory( ).
" the OK button closes the dialog roundtrip-free (the original's
" press handler is a plain this.oDialog.close())
DATA(dialog) = popup->ele( n = `FragmentDefinition` ns = `core`
)->a( n = `xmlns:core` v = `sap.ui.core`
)->a( n = `xmlns` v = `sap.m`
)->ele( `Dialog`
)->a( n = `type` v = `Message`
)->a( n = `title` v = title ).
" the default dialog is the only one the original builds without a state
IF state IS NOT INITIAL.
dialog->a( n = `state` v = state ).
ENDIF.
dialog->ele( `content`
)->tag( `Text`
)->a( n = `text` v = text
)->end(
)->ele( `beginButton`
)->tag( `Button`
)->a( n = `type` v = `Emphasized`
)->a( n = `text` v = `OK`
)->a( n = `press` v = client->follow_up_action( client->cs_event-popup_close ) ).
client->popup_display( popup->stringify( ) ).
ENDMETHOD.
METHOD model_init.
" the sample has no model - the five dialogs are built from literals
ENDMETHOD.
ENDCLASS.
More in sap.m
- Carousel with Multiple Items at Once — The customLayout aggregation determines how many pages are displayed in Carousel's visibl…
- Date Picker - Value States — This example shows different DatePicker value states.
- Date Range Selection - Value States — This example shows different DateRangeSelection value states.
- Date Time Picker - Value States — This example shows different DateTimePicker value states.
- Date Range Selection - Open by Another Control — This example shows Date Range Selection which is opened by another control.
- Date Time Picker - Open by Another Control — This example shows Date Time Picker which is opened by another control.
- Dialog - Fullscreen — A dialog that can be toggled to fullscreen mode through a header button, by double-clicki…
- Tile Statuses — Shows the GenericTile while it is loading, if loading fails, and in disabled status.
- List - Growing — The Growing feature helps if your content is too big to be loaded/shown at once. It pagin…
- Table - ContextualWidth (Dynamic) — This example shows the container-based pop-in behavior. The container has dynamic width.
- Message Box — MessageBox is an easy way of displaying a message-type dialog to the user. You can displa…
- Image error handling with IllustratedMessage — Handle errors using the sap.m.IllustratedMessage with the error event.
On this page