abap2UI5

Message Box

MessageBox is an easy way of displaying a message-type dialog to the user. You can display different types of dialogs: - Types of message (Alert, Confirmation, etc.) - Initial focus can be set to the buttons or the controls used in the message

Z2UI5_CL_SMPC_APP_278

Controls sap.m UI5 1.71

The facts

Repository
abap2UI5/samples-controls
Class
Z2UI5_CL_SMPC_APP_278
Source file
z2ui5_cl_smpc_app_278.clas.abap ↗
Library
sap.m
UI5 entity
sap.m.MessageBox
Demo kit sample
sap.m.sample.MessageBox
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: messagebox, message, box, sap.m, verticallayout, text, button

Controls it builds

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_278.clas.abap — 181 lines Read it on GitHub ↗
" @keywords messagebox message box sap.m verticallayout text button
" @summary MessageBox is an easy way of displaying a message-type dialog to the user. You can display different types of dialogs: - Types of message (Alert, Confirmation, etc.) - Initial focus can be set to the buttons or the controls used in the message
" @origin sap.m.sample.MessageBox - https://sdk.openui5.org/entity/sap.m.MessageBox/sample/sap.m.sample.MessageBox (status: checked - verified in a running system)
CLASS z2ui5_cl_smpc_app_278 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.
    METHODS on_event.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smpc_app_278 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    me->client = client.
    IF 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:mvc` v = `sap.ui.core.mvc`
        )->a( n = `xmlns:l`   v = `sap.ui.layout`

        )->ele( n = `VerticalLayout` ns = `l`
            " id added as the dependentOn anchor of the two message boxes below
            )->a( n = `id`    v = `messageBoxHost`
            )->a( n = `class` v = `sapUiContentPadding`
            )->a( n = `width` v = `100%`

            )->tag( `Text`
                )->a( n = `text` v = `Default Behavior`

            )->tag( `Button`
                )->a( n = `text`  v = `Confirm`
                )->a( n = `class` v = `sapUiSmallMarginBottom`
                )->a( n = `press` v = client->_event( `CONFIRM` )
                )->a( n = `width` v = `280px`
            )->tag( `Button`
                )->a( n = `text`  v = `Alert`
                )->a( n = `class` v = `sapUiSmallMarginBottom`
                )->a( n = `press` v = client->_event( `ALERT` )
                )->a( n = `width` v = `280px`
            )->tag( `Button`
                )->a( n = `text`  v = `Error`
                )->a( n = `class` v = `sapUiSmallMarginBottom`
                )->a( n = `press` v = client->_event( `ERROR` )
                )->a( n = `width` v = `280px`
            )->tag( `Button`
                )->a( n = `text`  v = `Info`
                )->a( n = `class` v = `sapUiSmallMarginBottom`
                )->a( n = `press` v = client->_event( `INFO` )
                )->a( n = `width` v = `280px`
            )->tag( `Button`
                )->a( n = `text`  v = `Warning`
                )->a( n = `class` v = `sapUiSmallMarginBottom`
                )->a( n = `press` v = client->_event( `WARNING` )
                )->a( n = `width` v = `280px`
            )->tag( `Button`
                )->a( n = `text`  v = `Success`
                )->a( n = `class` v = `sapUiSmallMarginBottom`
                )->a( n = `press` v = client->_event( `SUCCESS` )
                )->a( n = `width` v = `280px`

            )->tag( `Text`
                )->a( n = `text` v = `More Actions`

            )->tag( `Button`
                )->a( n = `text`  v = `Error with custom action`
                )->a( n = `class` v = `sapUiSmallMarginBottom`
                )->a( n = `press` v = client->_event( `ERROR_CUSTOM_ACTION` )
                )->a( n = `width` v = `280px`
            )->tag( `Button`
                )->a( n = `text`  v = `Warning with two actions`
                )->a( n = `class` v = `sapUiSmallMarginBottom`
                )->a( n = `press` v = client->_event( `WARNING_TWO_ACTIONS` )
                )->a( n = `width` v = `280px`
            )->tag( `Button`
                )->a( n = `text`  v = `Message Box with Responsive Padding`
                )->a( n = `class` v = `sapUiSmallMarginBottom`
                )->a( n = `press` v = client->_event( `RESPONSIVE_PADDING` )
                )->a( n = `width` v = `280px` ).

    client->view_display( view->stringify( ) ).

  ENDMETHOD.


  METHOD on_event.

    CASE client->get_event( ).

      WHEN `CONFIRM`.

        client->message_box_display( text = `Approve purchase order 12345?` type = `confirm` ).

      WHEN `ALERT`.

        client->message_box_display(
          text = `The quantity you have reported exceeds the quantity planed.`
          type = `alert` ).

      WHEN `ERROR`.

        client->message_box_display(
          text = |Select a team in the "Development" area.\n"Marketing" isn't assigned to this area.|
          type = `error` ).

      WHEN `INFO`.

        client->message_box_display( text = `Your booking will be reserved for 24 hours.` type = `information` ).

      WHEN `WARNING`.

        client->message_box_display( text = `The project schedule was last updated over a year ago.` type = `warning` ).

      WHEN `SUCCESS`.

        client->message_box_display(
          text = `Project 1234567 was created and assigned to team "ABC".`
          type = `success` ).

      WHEN `RESPONSIVE_PADDING`.

        client->message_box_display(
          text       = `This Message Box has responsive paddings which will adjust based on its content width!`
          type       = `information`
          styleclass = `sapUiResponsivePadding--header sapUiResponsivePadding--content sapUiResponsivePadding--footer` ).

      WHEN `ERROR_CUSTOM_ACTION`.

        " dependentOn is a sap.m.MessageBox option, so the box travels as the
        " control call it is - the type is the method, the options are the UI5
        " option object. It ties the box to the layout's lifecycle (original:
        " this.getView()); onClose stays a BACKEND event name
        client->follow_up_action(
            val   = client->cs_event-control_global
            t_arg = VALUE #( ( `MESSAGE_BOX` )
                             ( `error` )
                             ( `Product A does not exist.` )
                             ( `{"actions":["Manage Products","CLOSE"],"emphasizedAction":"Manage Products",` &&
                               `"onClose":"ACTION_SELECTED","dependentOn":"messageBoxHost"}` ) ) ).

      WHEN `WARNING_TWO_ACTIONS`.

        " dependentOn as above
        client->follow_up_action(
            val   = client->cs_event-control_global
            t_arg = VALUE #( ( `MESSAGE_BOX` )
                             ( `warning` )
                             ( `The quantity you have reported exceeds the quantity planned.` )
                             ( `{"actions":["OK","CANCEL"],"emphasizedAction":"OK",` &&
                               `"onClose":"ACTION_SELECTED","dependentOn":"messageBoxHost"}` ) ) ).

      WHEN `ACTION_SELECTED`.

        " the pressed action rides back as the first event argument
        client->message_toast_display( |Action selected: { client->get_event_arg( ) }| ).

    ENDCASE.

  ENDMETHOD.

ENDCLASS.

More in sap.m

Search every abap2UI5 sample · the full list on one page

On this page