|
1 | 1 | --- |
2 | 2 | outline: [2, 4] |
3 | 3 | --- |
4 | | -# App State |
| 4 | +# App State, Share, Bookmark |
5 | 5 |
|
6 | | -abap2UI5 saves the current app state so you can return to it later — like how standard UI5 apps manage state. |
| 6 | +abap2UI5 saves the current app state so you can return to it later — like how standard UI5 apps manage state. This opens up several useful options, like sharing and bookmarking the current state of your app. |
7 | 7 |
|
8 | 8 | ### Usage |
9 | 9 | Each state persists as a draft with a unique ID. Calling `client->set_app_state_active` appends this ID as a hash fragment to the URL. The resulting URL is shareable — copy it and open it in another browser window (or send it to a colleague) to restore the same app state. The hash value (`z2ui5-xapp-state=...`) is a server-side key that points to the saved draft. Drafts expire after a configurable time (default: 4 hours, adjustable via [User Exits](/advanced/extensibility/user_exits)). |
@@ -47,3 +47,40 @@ ENDCLASS. |
47 | 47 | ``` |
48 | 48 |
|
49 | 49 | For a complete implementation, see sample `Z2UI5_CL_DEMO_APP_321`. |
| 50 | + |
| 51 | +### Share |
| 52 | +Add a share button that copies the current state to the clipboard to share with colleagues: |
| 53 | +```abap |
| 54 | +CLASS z2ui5_cl_sample_share DEFINITION PUBLIC. |
| 55 | +
|
| 56 | + PUBLIC SECTION. |
| 57 | + INTERFACES z2ui5_if_app. |
| 58 | + DATA mv_quantity TYPE string. |
| 59 | +
|
| 60 | +ENDCLASS. |
| 61 | +
|
| 62 | +CLASS z2ui5_cl_sample_share IMPLEMENTATION. |
| 63 | + METHOD z2ui5_if_app~main. |
| 64 | +
|
| 65 | + CASE abap_true. |
| 66 | +
|
| 67 | + WHEN client->check_on_navigated( ). |
| 68 | +
|
| 69 | + DATA(view) = z2ui5_cl_xml_view=>factory( )->shell( )->page( |
| 70 | + )->label( `quantity` |
| 71 | + )->input( client->_bind_edit( mv_quantity ) |
| 72 | + )->button( text = `share` press = client->_event( `BUTTON_POST` ) ). |
| 73 | + client->view_display( view->stringify( ) ). |
| 74 | +
|
| 75 | + WHEN client->check_on_event( `BUTTON_POST` ). |
| 76 | +
|
| 77 | + client->follow_up_action( client->_event_client( z2ui5_if_client=>cs_event-CLIPBOARD_APP_STATE ) ). |
| 78 | + client->message_toast_display( `clipboard copied` ). |
| 79 | +
|
| 80 | + ENDCASE. |
| 81 | + ENDMETHOD. |
| 82 | +ENDCLASS. |
| 83 | +``` |
| 84 | + |
| 85 | +### Bookmark |
| 86 | +You can also use these URLs for bookmarking, but note that the server keeps the app state only for a limited time. The default is 4 hours. See the [draft service](https://github.com/abap2UI5/abap2UI5/blob/main/src/01/01/z2ui5_cl_core_srv_draft.clas.abap#L46) source. |
0 commit comments