Hash
Hash routing in mode FRESH: the URL names the CLASS, so Back and a bookmark restart the app as a new instance.
Z2UI5_CL_SMP_APP_468
Learn
Hash
UI5 1.71
The facts
- Repository
- abap2UI5/samples
- Class
Z2UI5_CL_SMP_APP_468- Source file
z2ui5_cl_smp_app_468.clas.abap↗- Category
- Hash
- Learning path
- Move through the app
- 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/navigatio… ↗
Keywords: routing, mode, fresh, navigation, restart, new, instance, nav_app_call
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
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_468.clas.abap — 133 lines
Click a number to link to a line — shift-click for a range.
Read it on GitHub ↗
" @keywords routing mode fresh navigation restart new instance nav_app_call
" @summary Hash routing in mode FRESH: the URL names the CLASS, so Back and a bookmark restart the app as a new instance.
" @docs https://abap2ui5.github.io/docs/cookbook/event_navigation/navigation/hash
"! Hash-based app routing (UI5 Router style), mode FRESH:
"! follow_up_action( cs_event-hash_routing ) with mode FRESH makes the URL
"! mirror the running app by CLASS only ('#/app/[CLASS]'). Browser Back/Forward - and a
"! reload or a bookmark - therefore start the app FRESH: the input and the
"! counter are gone.
"!
"! Put in some state (type / raise the counter), open the detail page
"! (z2ui5_cl_smp_app_469) via client->nav_app_call( ), then press the BROWSER
"! Back button and watch this page - it comes back empty.
"!
"! z2ui5_cl_smp_app_480 is the same demo in mode KEEP, where the state survives.
CLASS z2ui5_cl_smp_app_468 DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
DATA input TYPE string.
DATA counter TYPE i.
PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.
METHODS on_event.
METHODS view_display.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_smp_app_468 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 on_event.
CASE client->get_event( ).
WHEN `INC`.
counter = counter + 1.
view_display( ).
WHEN `GO_DETAIL`.
client->nav_app_call( NEW z2ui5_cl_smp_app_469( ) ).
ENDCASE.
ENDMETHOD.
METHOD view_display.
" configure the routing mode once - the framework remembers it on the app
" and re-sends it whenever the frontend may not hold it (page load,
" Back/Forward restore, navigation hops)
IF client->check_on_init( ).
client->follow_up_action( val = client->cs_event-hash_routing
t_arg = VALUE #( ( client->cs_nav_mode-fresh ) ) ).
ENDIF.
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`
)->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 - Routing Mode fresh`
)->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 = `Add some state (type / raise the counter), open the detail page, then press your ` &&
`BROWSER Back button and watch this page.`
)->a( n = `type` v = `Information`
)->a( n = `showIcon` b = abap_true
)->a( n = `class` v = `sapUiSmallMargin` ).
DATA(form) = 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 = `Routing mode fresh`
)->ele( n = `content` ns = `form` ).
form->tag( `Label`
)->a( n = `text` v = `1. Some state - type here` ).
form->tag( `Input`
)->a( n = `value` v = client->_bind( input ) ).
form->tag( `Label`
)->a( n = `text` v = `and raise a counter` ).
form->tag( `Button`
)->a( n = `press` v = client->_event( `INC` )
)->a( n = `text` v = |increment ({ counter })| ).
form->tag( `Label`
)->a( n = `text` v = `2. Navigate forward` ).
form->tag( `Button`
)->a( n = `press` v = client->_event( `GO_DETAIL` )
)->a( n = `text` v = `go to the detail page (nav_app_call)`
)->a( n = `type` v = `Emphasized` ).
page->tag( `MessageStrip`
)->a( n = `text` v = `fresh: the URL carries the class only (#/app/<CLASS>). After the detail page, the ` &&
`browser Back button starts this app FRESH - input and counter are reset.`
)->a( n = `type` v = `Success`
)->a( n = `showIcon` b = abap_true
)->a( n = `class` v = `sapUiSmallMargin` ).
client->view_display( view->stringify( ) ).
ENDMETHOD.
ENDCLASS.
More in Hash
On this page