You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/development/events.md
+49-29Lines changed: 49 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,13 @@ outline: [2, 4]
3
3
---
4
4
# Events
5
5
6
-
### Frontend
6
+
UI5 Control properties can be used not only to display data but also to trigger events. Let’s explore how we can leverage this functionality.
7
7
8
-
#### Basic
8
+
### Backend
9
+
You can trigger backend processing when an event occurs using the `client->_event` method.
9
10
10
-
If an UI5 property is an event, just import the result of the method `client->_event` to trigger events in the backend. Check out the event with the value `client->get( )-event`:
11
+
#### Basic
12
+
As an example, we will use the `press` property of a button. To trigger events in the backend, assign the result of `client->_event('MY_EVENT_NAME')` to the relevant UI5 control property. Once triggered, the backend can retrieve the event details with `client->get( )-event`.
11
13
12
14
```abap
13
15
METHOD z2ui5_if_app~main.
@@ -25,16 +27,16 @@ METHOD z2ui5_if_app~main.
25
27
26
28
ENDMETHOD.
27
29
```
30
+
If the backend requires additional information about the specific event, use parameters like `$event`, `$source`, and `$params` to send further details. Use the t_arg parameter to include these details. See (this documentation)[(https://openui5.hana.ondemand.com/#/topic/b0fb4de7364f4bcbb053a99aa645affe)] for more information, and refer to sample `Z2UI5_CL_DEMO_APP_167`.
28
31
29
-
Sometimes the backend needs more information about the süpecific event, you can use the parameter `$event`, `$source` and `$params` to send further information into the backend. Therefore use the parameter `t_arg`. Check the documentation [here.](https://openui5.hana.ondemand.com/#/topic/b0fb4de7364f4bcbb053a99aa645affe). Check out sampple `Z2UI5_CL_DEMO_APP_167`:
30
-
31
-
#### Source Properties
32
-
Send properties of the event source control:
32
+
#### Source
33
+
Send properties of the event source control to the backend:
33
34
```abap
34
35
METHOD z2ui5_if_app~main.
35
36
36
37
client->view_display( z2ui5_cl_xml_view=>factory(
37
-
)->button( text = `post` press = client->_event( val = `BUTTON_POST`
38
+
)->button( text = `post` press = client->_event(
39
+
val = `BUTTON_POST`
38
40
t_arg = VALUE #( ( `${$source>/text}` ) ) )
39
41
)->stringify( ) ).
40
42
@@ -46,66 +48,83 @@ METHOD z2ui5_if_app~main.
46
48
ENDMETHOD.
47
49
```
48
50
49
-
#### Event Parameters
50
-
Read Event Parameters:
51
+
#### Parameters
52
+
Retrieve parameters of the event:
51
53
```abap
52
54
METHOD z2ui5_if_app~main.
53
55
54
56
client->view_display( z2ui5_cl_xml_view=>factory(
55
-
)->button( text = `post` press = client->_event( val = `BUTTON_POST`
56
-
t_arg = VALUE #( ( `${$source>/text}` ) ) )
57
+
)->button( text = `post` id = `button_id` press = client->_event(
58
+
val = `BUTTON_POST`
59
+
t_arg = VALUE #( ( `${$parameters>/id}` ) ) )
57
60
)->stringify( ) ).
58
61
59
62
CASE client->get( )-event.
60
63
WHEN 'BUTTON_POST'.
61
-
client->message_box_display( |The button text is { client->get_event_arg( ) }| ).
64
+
"mainView--button_id
65
+
client->message_box_display( |The button id is { client->get_event_arg( ) }| ).
62
66
ENDCASE.
63
67
64
68
ENDMETHOD.
65
69
```
66
70
67
-
#### Event Properties
68
-
Read Event Parameters:
71
+
#### Event
72
+
Retrieve specific properties of the event:
69
73
```abap
70
74
METHOD z2ui5_if_app~main.
71
75
72
76
client->view_display( z2ui5_cl_xml_view=>factory(
73
-
)->button( text = `post` press = client->_event( val = `BUTTON_POST`
74
-
t_arg = VALUE #( ( `${$source>/text}` ) ) )
77
+
)->button( text = `post` press = client->_event(
78
+
val = `BUTTON_POST`
79
+
t_arg = VALUE #( ( `$event>sId` ) ) )
75
80
)->stringify( ) ).
76
81
77
82
CASE client->get( )-event.
78
83
WHEN 'BUTTON_POST'.
79
-
client->message_box_display( |The button text is { client->get_event_arg( ) }| ).
84
+
"press
85
+
client->message_box_display( |The evend id is { client->get_event_arg( ) }| ).
80
86
ENDCASE.
81
87
82
88
ENDMETHOD.
83
89
```
90
+
::: warning
91
+
You can access any object attribute, but ensure you access only public and released attributes to avoid compatibility issues with future UI5 versions.
92
+
:::
84
93
85
94
#### Model Properties
86
-
Read Event Parameters:
95
+
Retrieve model properties associated with the event:
87
96
```abap
97
+
CLASS z2ui5_cl_app_hello_world DEFINITION PUBLIC CREATE PUBLIC.
98
+
99
+
PUBLIC SECTION.
100
+
INTERFACES z2ui5_if_app.
101
+
DATA name TYPE string.
102
+
103
+
ENDCLASS.
104
+
88
105
METHOD z2ui5_if_app~main.
89
106
90
107
client->view_display( z2ui5_cl_xml_view=>factory(
108
+
)->input( client->_bind_edit( name )
91
109
)->button( text = `post` press = client->_event(
92
110
val = `BUTTON_POST`
93
-
t_arg = VALUE #( ( `${$source>/text}` ) ) )
111
+
t_arg = VALUE #( ( `$` && client->_bind_edit( name ) ) ) )
94
112
)->stringify( ) ).
95
113
96
114
CASE client->get( )-event.
97
115
WHEN 'BUTTON_POST'.
98
-
client->message_box_display( |The button text is { client->get_event_arg( ) }| ).
116
+
client->message_box_display( |The name is { client->get_event_arg( ) }| ).
99
117
ENDCASE.
100
-
118
+
101
119
ENDMETHOD.
102
120
```
103
121
104
-
### Frontend
105
-
106
-
#### Event Frontend
122
+
::: tipp
123
+
This is just a demonstration. In this case, it would be easier to access `mv_name` directly since it’s automatically updated by the framework.
124
+
:::
107
125
108
-
The following frontend events re availibkle:
126
+
### Frontend
127
+
If you dont want to process the event in the backend, you can also directly trigger actions at the frontend. The following frontend events re availibkle:
109
128
```abap
110
129
CONSTANTS:
111
130
BEGIN OF cs_event,
@@ -123,7 +142,7 @@ The following frontend events re availibkle:
123
142
set_size_limit TYPE string VALUE `SET_SIZE_LIMIT`,
124
143
END OF cs_event.
125
144
```
126
-
145
+
For example, to open a new tab with the corresponding event:
127
146
```abap
128
147
METHOD z2ui5_if_app~main.
129
148
@@ -138,7 +157,8 @@ METHOD z2ui5_if_app~main.
138
157
ENDMETHOD.
139
158
```
140
159
141
-
#### Follow Up Action
160
+
### Follow Up Action
161
+
Sometimes, you might want to first call a backend function and then immediately perform an action in the frontend. This is possible with the follow-up action event:
142
162
```abap
143
163
METHOD z2ui5_if_app~main.
144
164
@@ -148,4 +168,4 @@ METHOD z2ui5_if_app~main.
148
168
149
169
ENDMETHOD.
150
170
```
151
-
Check out sample `Z2UI5_CL_DEMO_APP_180` for a working snippet.
171
+
Refer to sample `Z2UI5_CL_DEMO_APP_180` for a working example of this functionality.
0 commit comments