abap2UI5

Basics III

The three questions main( ) asks - init, event, navigated - as one dispatcher, showing what survives a roundtrip and what a navigation does to it.

Z2UI5_CL_SMP_APP_495

Learn Basics UI5 1.71

The facts

Repository
abap2UI5/samples
Class
Z2UI5_CL_SMP_APP_495
Source file
z2ui5_cl_smp_app_495.clas.abap
Category
Basics
Learning path
Start here
Minimum UI5
1.71 — the floor abap2UI5 holds its samples to
In the playground
runs in the browser, with no system and nothing installed
Documentation
abap2ui5.github.io/docs/cookbook/event_navigation/life_cycle ↗

Keywords: lifecycle, roundtrip, main, dispatcher, state, serialize, check_on_init, check_on_event, check_on_navigated

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_495.clas.abap — 110 lines Read it on GitHub ↗
" @keywords lifecycle roundtrip main dispatcher state serialize check_on_init check_on_event check_on_navigated
" @summary The three questions main( ) asks - init, event, navigated - as one dispatcher, showing what survives a roundtrip and what a navigation does to it.
" @docs https://abap2ui5.github.io/docs/cookbook/event_navigation/life_cycle https://abap2ui5.github.io/docs/cookbook/expert_more/snippets https://abap2ui5.github.io/docs/tutorials/walkthrough/step-3
CLASS z2ui5_cl_smp_app_495 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    TYPES:
      BEGIN OF ty_s_step,
        no    TYPE string,
        check TYPE string,
      END OF ty_s_step.
    DATA t_log TYPE STANDARD TABLE OF ty_s_step WITH EMPTY KEY.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS log_step
      IMPORTING
        val TYPE string.
    METHODS view_display.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smp_app_495 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

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

      log_step( `check_on_init( ) - the very first call, nothing exists yet` ).
      view_display( ).

    ELSEIF client->check_on_navigated( ).

      log_step( `check_on_navigated( ) - the sub-app returned, re-display the view` ).
      view_display( ).

    ELSEIF client->check_on_event( `LOG` ).
      log_step( `check_on_event( ) - a button was pressed, the view stays as it is` ).

    ELSEIF client->check_on_event( `CALL` ).

      log_step( `check_on_event( ) - calling Basics I as a sub-app` ).
      client->nav_app_call( NEW z2ui5_cl_smp_app_493( ) ).

    ENDIF.

  ENDMETHOD.


  METHOD log_step.

    INSERT VALUE #( no = |{ lines( t_log ) + 1 }| check = val ) INTO TABLE t_log.

  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 - Basics III - Lifecycle: Init, Event, Navigated`
            )->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 = `main( ) runs on every roundtrip - the three checks tell it what the ` &&
                   `roundtrip is about. The list logs each call, and it survives them all: ` &&
                   `every public attribute is serialized between the roundtrips, so the app ` &&
                   `keeps its state without a database. Press Log - only the model is pushed, ` &&
                   `the view is not rebuilt. Call the sub-app and come back with its back ` &&
                   `button - that is the roundtrip check_on_navigated( ) answers.`
        )->a( n = `type`     v = `Information`
        )->a( n = `showIcon` b = abap_true
        )->a( n = `class`    v = `sapUiSmallMargin` ).

    page->ele( `HBox`
        )->a( n = `class` v = `sapUiSmallMargin`
        )->tag( `Button`
            )->a( n = `press` v = client->_event( `LOG` )
            )->a( n = `text`  v = `Log an Event`
        )->tag( `Button`
            )->a( n = `press` v = client->_event( `CALL` )
            )->a( n = `text`  v = `Call a Sub-App`
            )->a( n = `class` v = `sapUiTinyMarginBegin` ).

    page->ele( `List`
        )->a( n = `headerText` v = `Calls of main( )`
        )->a( n = `items`      v = client->_bind( t_log )
        )->a( n = `class`      v = `sapUiSmallMargin`
        )->tag( `StandardListItem`
            )->a( n = `title`       v = `{CHECK}`
            )->a( n = `description` v = `call {NO}` ).

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

  ENDMETHOD.
ENDCLASS.

More in Basics

Search every abap2UI5 sample · the full list on one page

On this page