|
| 1 | +CLASS z2ui5_cl_demo_app_467 DEFINITION PUBLIC. |
| 2 | + |
| 3 | + PUBLIC SECTION. |
| 4 | + INTERFACES z2ui5_if_app. |
| 5 | + |
| 6 | + TYPES: |
| 7 | + BEGIN OF ty_s_message, |
| 8 | + message TYPE string, |
| 9 | + description TYPE string, |
| 10 | + type TYPE string, |
| 11 | + target TYPE string, |
| 12 | + additionaltext TYPE string, |
| 13 | + END OF ty_s_message. |
| 14 | + DATA t_messages TYPE STANDARD TABLE OF ty_s_message WITH EMPTY KEY. |
| 15 | + DATA name TYPE string. |
| 16 | + |
| 17 | + PROTECTED SECTION. |
| 18 | + DATA client TYPE REF TO z2ui5_if_client. |
| 19 | + |
| 20 | + METHODS view_display. |
| 21 | + |
| 22 | + PRIVATE SECTION. |
| 23 | +ENDCLASS. |
| 24 | + |
| 25 | + |
| 26 | +CLASS z2ui5_cl_demo_app_467 IMPLEMENTATION. |
| 27 | + |
| 28 | + METHOD z2ui5_if_app~main. |
| 29 | + |
| 30 | + me->client = client. |
| 31 | + IF client->check_on_init( ). |
| 32 | + |
| 33 | + " app-authored messages - the controller's MessageManager.addMessages |
| 34 | + " equivalent. The z2ui5.cc.MessageManager companion reconciles this |
| 35 | + " table into the central message manager: each row becomes a |
| 36 | + " sap.ui.core.message.Message with the view's model as processor, so a |
| 37 | + " row with a target sets that field's valueState too. |
| 38 | + t_messages = VALUE #( |
| 39 | + ( message = `Please enter a valid name` |
| 40 | + type = `Error` |
| 41 | + additionaltext = `Name` |
| 42 | + target = `/NAME` ) |
| 43 | + ( message = `Draft saved automatically` |
| 44 | + type = `Information` |
| 45 | + additionaltext = `Autosave` ) ). |
| 46 | + |
| 47 | + view_display( ). |
| 48 | + |
| 49 | + ENDIF. |
| 50 | + |
| 51 | + ENDMETHOD. |
| 52 | + |
| 53 | + |
| 54 | + METHOD view_display. |
| 55 | + |
| 56 | + DATA(view) = z2ui5_cl_xml_view=>factory( ). |
| 57 | + |
| 58 | + DATA(page) = view->shell( |
| 59 | + )->page( |
| 60 | + title = `abap2UI5 - Messages - app-authored via z2ui5.cc.MessageManager` |
| 61 | + navbuttonpress = client->_event_nav_app_leave( ) |
| 62 | + shownavbutton = client->check_app_prev_stack( ) ). |
| 63 | + |
| 64 | + page->message_strip( |
| 65 | + text = `The messages below are authored by the app (not collected from control validation) ` && |
| 66 | + `and pushed into the central message model by the invisible z2ui5.cc.MessageManager ` && |
| 67 | + `companion bound to an ABAP table - the Error targets the Name field and colours it.` |
| 68 | + type = `Information` |
| 69 | + showicon = abap_true |
| 70 | + class = `sapUiSmallMargin` ). |
| 71 | + |
| 72 | + " invisible companion control: reconciles /T_MESSAGES into the message |
| 73 | + " manager (adds the app's messages, removes its own when they drop out, |
| 74 | + " leaves auto-collected validation untouched) |
| 75 | + page->_generic( name = `MessageManager` |
| 76 | + ns = `z2ui5` |
| 77 | + t_prop = VALUE #( ( n = `items` v = client->_bind( t_messages ) ) ) ). |
| 78 | + |
| 79 | + page->simple_form( title = `Registration` |
| 80 | + editable = abap_true |
| 81 | + class = `sapUiSmallMargin` |
| 82 | + )->content( |
| 83 | + )->label( `Name` |
| 84 | + )->input( client->_bind_edit( name ) ). |
| 85 | + |
| 86 | + page->list( headertext = `Collected messages (message> model)` |
| 87 | + items = `{message>/}` |
| 88 | + class = `sapUiSmallMargin` |
| 89 | + )->standard_list_item( title = `{message>message}` |
| 90 | + description = `{message>additionalText}` |
| 91 | + info = `{message>type}` ). |
| 92 | + |
| 93 | + client->view_display( view->stringify( ) ). |
| 94 | + |
| 95 | + ENDMETHOD. |
| 96 | + |
| 97 | +ENDCLASS. |
0 commit comments