Samples / Learn / Navigation

Navigation

Calling another app and coming back: nav_app_call puts the caller on a stack, nav_app_leave returns to it.

Class
z2ui5_cl_smp_app_024
Repository
abap2UI5/samples
UI5 libraries
sap.m, sap.ui.core, sap.ui.layout
Lowest UI5 release
1.71
In the browser
Runs in the playground
Controls it builds
sap.m.Button, sap.m.Input, sap.m.Label, sap.m.MessageStrip, sap.m.Page, sap.m.Shell, sap.ui.core.mvc.View, sap.ui.layout.Grid, sap.ui.layout.form.SimpleForm
Documentation
cookbook/event_navigation/navigation/inner_app ↗

The class

" @keywords nav_app_call nav_app_leave sub app stack call back
" @summary Calling another app and coming back: nav_app_call puts the caller on a stack, nav_app_leave returns to it.
" @docs https://abap2ui5.github.io/docs/cookbook/event_navigation/navigation/inner_app
CLASS z2ui5_cl_smp_app_024 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    DATA input  TYPE string.
    DATA input2 TYPE string.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS on_event.
    METHODS view_display.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smp_app_024 IMPLEMENTATION.


  METHOD z2ui5_if_app~main.

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

      " abap2ui5lint-disable-next-line handler-without-event -- handed over by z2ui5_cl_smp_app_025 with nav_app_leave( event = ... )
      IF client->get_event( ) = `CALL_PREVIOUS_APP_INPUT_RETURN`.

        DATA(app_025) = CAST z2ui5_cl_smp_app_025( client->get_app_prev( ) ).
        client->message_box_display( |Input made in the previous app: { app_025->input }| ).

      ENDIF.

      view_display( ).

    ELSEIF client->check_on_event( ).
      on_event( ).
    ENDIF.

  ENDMETHOD.


  METHOD on_event.

    CASE client->get_event( ).

      WHEN `CALL_NEW_APP`.
        client->nav_app_call( NEW z2ui5_cl_smp_app_025( ) ).

      WHEN `CALL_NEW_APP_VIEW`.
        DATA(app) = NEW z2ui5_cl_smp_app_025( ).
        app->show_view = `SECOND`.
        client->nav_app_call( app ).

      WHEN `CALL_NEW_APP_READ`.
        DATA(app_next) = NEW z2ui5_cl_smp_app_025( ).
        app_next->input_previous_set = input.
        client->nav_app_call( app_next ).

      WHEN `CALL_NEW_APP_EVENT`.
        app_next = NEW z2ui5_cl_smp_app_025( ).
        app_next->event_backend = `NEW_APP_EVENT`.
        client->nav_app_call( app_next ).

    ENDCASE.

  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:form`   v = `sap.ui.layout.form`
            )->a( n = `xmlns:layout` v = `sap.ui.layout` ).
    DATA(page) = view->ele( `Shell`
        )->ele( `Page`
            )->a( n = `title`          v = `abap2UI5 - Navigation - Call and Leave Apps (nav_app_call)`
            )->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 = `App-to-app navigation: calls a second app in different ways - open a view, raise ` &&
                   `an event or pass data - and reads the input it returns.`
        )->a( n = `type`     v = `Information`
        )->a( n = `showIcon` b = abap_true
        )->a( n = `class`    v = `sapUiSmallMargin` ).

    page->ele( n = `Grid` ns = `layout`
        )->a( n = `defaultSpan` v = `L6 M12 S12`
        )->ele( n = `content` ns = `layout`
            )->ele( n = `SimpleForm` ns = `form`
                )->a( n = `title`    v = `Controller`
                )->a( n = `editable` b = abap_true
                )->ele( n = `content` ns = `form`
                    )->tag( `Label`
                        )->a( n = `text` v = `Demo`
                    )->tag( `Button`
                        )->a( n = `press` v = client->_event( `CALL_NEW_APP` )
                        )->a( n = `text`  v = `call new app (first View)`
                    )->tag( `Label`
                        )->a( n = `text` v = `Demo`
                    )->tag( `Button`
                        )->a( n = `press` v = client->_event( `CALL_NEW_APP_VIEW` )
                        )->a( n = `text`  v = `call new app (second View)`
                    )->tag( `Label`
                        )->a( n = `text` v = `Demo`
                    )->tag( `Button`
                        )->a( n = `press` v = client->_event( `CALL_NEW_APP_EVENT` )
                        )->a( n = `text`  v = `call new app (set Event)`
                    )->tag( `Label`
                        )->a( n = `text` v = `Demo`
                    )->tag( `Input`
                        )->a( n = `value` v = client->_bind( input )
                    )->tag( `Button`
                        )->a( n = `press` v = client->_event( `CALL_NEW_APP_READ` )
                        )->a( n = `text`  v = `call new app (set data)`
                    )->tag( `Label`
                        )->a( n = `text` v = `some data, you can read in the next app`
                    )->tag( `Input`
                        )->a( n = `value` v = client->_bind( input2 ) ).

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

  ENDMETHOD.
ENDCLASS.