abap2UI5

Menu

A nested Menu that reports the FULL path of the item that was chosen, not just its text.

Z2UI5_CL_SMP_APP_473

Learn Menu UI5 1.71

The facts

Repository
abap2UI5/samples
Class
Z2UI5_CL_SMP_APP_473
Source file
z2ui5_cl_smp_app_473.clas.abap
Category
Menu
Learning path
Talk to the user
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: menuitem, nested, submenu, textpath, controller, path

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_smp_app_473.clas.abap — 95 lines Read it on GitHub ↗
" @keywords menuitem nested submenu textpath controller path
" @summary A nested Menu that reports the FULL path of the item that was chosen, not just its text.
CLASS z2ui5_cl_smp_app_473 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smp_app_473 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    me->client = client.
    IF client->check_on_navigated( ).
      view_display( ).
    ENDIF.

  ENDMETHOD.


  METHOD view_display.

    DATA(view) = z2ui5_cl_ui5_view_builder=>factory(
        )->ele( n = `View` ns = `mvc`
            )->a( n = `displayBlock` v = `true`
            )->a( n = `height`       v = `100%`
            )->a( n = `xmlns`        v = `sap.m`
            )->a( n = `xmlns:mvc`    v = `sap.ui.core.mvc`
            )->a( n = `xmlns:core`   v = `sap.ui.core` ).

    DATA(page) = view->ele( `Shell`
        )->ele( `Page`
            )->a( n = `title`          v = `abap2UI5 - Menu - Full Path of the Selected Item`
            )->a( n = `showNavButton`  b = client->check_app_prev_stack( )
            )->a( n = `navButtonPress` v = client->_event_nav_app_leave( ) ).

    page->tag( `MessageStrip`
        )->a( n = `text`     v = `The toast shows the full path of the selected menu item ` &&
                   `("Create New Site > Official Store"), not only its own text. ` &&
                   `$controller.textPath( ) walks the item's parent chain in the control tree ` &&
                   `and joins the texts - a walk no binding path can express. Everything happens ` &&
                   `on the client, the menu selection needs no roundtrip at all.`
        )->a( n = `type`     v = `Information`
        )->a( n = `showIcon` b = abap_true
        )->a( n = `class`    v = `sapUiSmallMargin` ).

    " the item's breadcrumb is resolved on the client and substituted into the
    " toast template ({0}); an argument starting with $ is a client-side
    " expression, everything else travels as a plain string
    DATA(menu_selected) = client->follow_up_action(
        val   = z2ui5_if_client=>cs_event-control_global
        t_arg = VALUE #( ( `MESSAGE_TOAST` )
                         ( `show` )
                         ( `Action triggered on item: {0}` )
                         ( `$controller.textPath(${$parameters>/item})` ) ) ).

    DATA(menu) = page->ele( `HBox`
        )->a( n = `class` v = `sapUiSmallMargin`
        )->ele( `MenuButton`
            )->a( n = `text` v = `Actions`
            )->ele( `Menu`
                )->a( n = `itemSelected` v = menu_selected ).

    menu->ele( `MenuItem`
        )->a( n = `text` v = `Create New Site`
        )->tag( `MenuItem`
            )->a( n = `text` v = `Official Store`
        )->tag( `MenuItem`
            )->a( n = `text` v = `Franchise Store`
        )->tag( `MenuItem`
            )->a( n = `text` v = `Pop-up Store` ).

    menu->ele( `MenuItem`
        )->a( n = `text` v = `Manage Users`
        )->tag( `MenuItem`
            )->a( n = `text` v = `Add User`
        )->tag( `MenuItem`
            )->a( n = `text` v = `Remove User` ).

    menu->tag( `MenuItem`
        )->a( n = `text` v = `Log Out` ).

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

  ENDMETHOD.

ENDCLASS.

More in Menu

Search every abap2UI5 sample · the full list on one page

On this page