Skip to content

Commit f933b31

Browse files
committed
Add explanations for hardest-to-read code snippets
- formatter.md: explain UI5 parts/type binding syntax, escaped curly braces in ABAP string templates, and path=abap_true usage with example showing ABAP→UI5 output mapping - expression_binding.md: add resolution table showing what ABAP string concatenation produces at runtime, inline comments in both snippets - trouble.md: explain z2ui5.afterBE hook pattern (define JS in script tag, execute via follow_up_action), add step-by-step inline comments - events.md: add per-snippet explanations for $source, $parameters, $event syntax with inline comments showing runtime results - odata.md: document metadata binding path pattern {MODEL>/#EntityType/Property/@SAP:annotation} with breakdown of each path segment https://claude.ai/code/session_01AaA4EMw83KMzGP6kaDZPJU
1 parent 5754230 commit f933b31

5 files changed

Lines changed: 82 additions & 23 deletions

File tree

docs/development/events.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,61 +36,62 @@ If the backend needs additional information about the specific event, use the `t
3636
Check out [this documentation](https://openui5.hana.ondemand.com/#/topic/b0fb4de7364f4bcbb053a99aa645affe) for more information, and refer to sample `Z2UI5_CL_DEMO_APP_167`.
3737

3838
#### Source
39-
Send properties of the event source control to the backend:
39+
Send properties of the event source control to the backend. The syntax `${$source>/text}` reads the `text` property from the UI5 control that fired the event — here the button itself, so the result is the button's label (`post`):
4040
```abap
4141
METHOD z2ui5_if_app~main.
4242
4343
client->view_display( z2ui5_cl_xml_view=>factory(
44-
)->button( text = `post` press = client->_event(
45-
val = `BUTTON_POST`
46-
t_arg = VALUE #( ( `${$source>/text}` ) ) )
44+
)->button( text = `post` press = client->_event(
45+
val = `BUTTON_POST`
46+
"reads button text → result: "post"
47+
t_arg = VALUE #( ( `${$source>/text}` ) ) )
4748
)->stringify( ) ).
48-
49+
4950
CASE client->get( )-event.
5051
WHEN `BUTTON_POST`.
5152
client->message_box_display( |The button text is { client->get_event_arg( ) }| ).
5253
ENDCASE.
53-
54+
5455
ENDMETHOD.
5556
```
5657

5758
#### Parameters
58-
Retrieve parameters of the event:
59+
Retrieve parameters of the event. The syntax `${$parameters>/id}` reads the `id` parameter from the event's parameter map — UI5 generates a qualified ID like `mainView--button_id`:
5960
```abap
6061
METHOD z2ui5_if_app~main.
6162
6263
client->view_display( z2ui5_cl_xml_view=>factory(
63-
)->button( text = `post` id = `button_id` press = client->_event(
64-
val = `BUTTON_POST`
65-
t_arg = VALUE #( ( `${$parameters>/id}` ) ) )
64+
)->button( text = `post` id = `button_id` press = client->_event(
65+
val = `BUTTON_POST`
66+
"reads event parameter 'id' → result: "mainView--button_id"
67+
t_arg = VALUE #( ( `${$parameters>/id}` ) ) )
6668
)->stringify( ) ).
67-
69+
6870
CASE client->get( )-event.
6971
WHEN `BUTTON_POST`.
70-
"mainView--button_id
7172
client->message_box_display( |The button id is { client->get_event_arg( ) }| ).
7273
ENDCASE.
73-
74+
7475
ENDMETHOD.
7576
```
7677

7778
#### Event
78-
Retrieve specific properties of the event:
79+
Retrieve specific properties of the event object. The syntax `$event>sId` accesses the `sId` attribute of the UI5 event — here it returns the event type name (`press`). Note: no `${...}` wrapper here because `$event` directly references the event object:
7980
```abap
8081
METHOD z2ui5_if_app~main.
8182
8283
client->view_display( z2ui5_cl_xml_view=>factory(
83-
)->button( text = `post` press = client->_event(
84-
val = `BUTTON_POST`
85-
t_arg = VALUE #( ( `$event>sId` ) ) )
84+
)->button( text = `post` press = client->_event(
85+
val = `BUTTON_POST`
86+
"reads event object attribute → result: "press"
87+
t_arg = VALUE #( ( `$event>sId` ) ) )
8688
)->stringify( ) ).
87-
89+
8890
CASE client->get( )-event.
8991
WHEN `BUTTON_POST`.
90-
"press
9192
client->message_box_display( |The event id is { client->get_event_arg( ) }| ).
9293
ENDCASE.
93-
94+
9495
ENDMETHOD.
9596
```
9697
::: warning

docs/development/model/expression_binding.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The syntax `{= ... }` marks a UI5 expression binding. Inside the expression, you
66

77
#### Calculate the Maximum Value at the Frontend
88

9+
The inputs use a UI5 type binding (`{ type: ..., path: "..." }`) to ensure integer validation. The third input uses an expression binding (`{= ... }`) to compute the maximum of both values directly in the browser. Here's what the ABAP string concatenation produces at runtime:
10+
11+
| ABAP code | UI5 binding result |
12+
|---|---|
13+
| `client->_bind( val = input31 path = abap_true )` | `/XX/INPUT31` (raw path for type binding) |
14+
| `client->_bind( input31 )` | `{/XX/INPUT31}` (full binding for expression) |
15+
| `` `{= Math.max($` && client->_bind( input31 ) && `, $` && client->_bind( input32 ) && `) }` `` | `{= Math.max(${/XX/INPUT31}, ${/XX/INPUT32}) }` |
16+
917
```abap
1018
CLASS z2ui5_cl_demo_app_max_val DEFINITION PUBLIC.
1119
@@ -22,12 +30,16 @@ CLASS z2ui5_cl_demo_app_max_val IMPLEMENTATION.
2230
DATA(view) = z2ui5_cl_xml_view=>factory( ).
2331
view->shell( )->page(
2432
)->label( `max value of the first two inputs`
33+
"UI5 type binding — validates integer input
34+
"resolves to: { type: "sap.ui.model.type.Integer", path: "/XX/INPUT31" }
2535
)->input( `{ type : "sap.ui.model.type.Integer",` &&
2636
` path:"` && client->_bind( val = input31
2737
path = abap_true ) && `" }`
2838
)->input( `{ type : "sap.ui.model.type.Integer",` && |\n| &&
2939
` path:"` && client->_bind( val = input32
3040
path = abap_true ) && `" }`
41+
"Expression binding — computed in the browser
42+
"resolves to: {= Math.max(${/XX/INPUT31}, ${/XX/INPUT32}) }
3143
)->input(
3244
value = `{= Math.max($` && client->_bind( input31 ) &&`, $` && client->_bind( input32 ) && `) }`
3345
enabled = abap_false ).
@@ -38,6 +50,9 @@ ENDCLASS.
3850
```
3951

4052
#### Conditionally Set Input Field Editability
53+
54+
The `enabled` property uses an expression binding that resolves to `{= 500===${/XX/QUANTITY} }` — the product field is only editable when the quantity is exactly 500. Note that `===` is the JavaScript strict equality operator.
55+
4156
```abap
4257
CLASS z2ui5_cl_demo_editable DEFINITION PUBLIC.
4358
@@ -57,6 +72,7 @@ CLASS z2ui5_cl_demo_editable IMPLEMENTATION.
5772
)->input( `{ type : "sap.ui.model.type.Integer",` &&
5873
` path:"` && client->_bind( val = quantity
5974
path = abap_true ) && `" }`
75+
"enabled resolves to: {= 500===${/XX/QUANTITY} }
6076
)->input(
6177
value = client->_bind_edit( product )
6278
enabled = `{= 500===$` && client->_bind( quantity ) && ` }` ).

docs/development/model/odata.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,19 @@ In SAP contexts, OData services are often enriched with additional annotations.
111111
<Property Name="IsPrimaryCurrencyForISOCrcy" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="primär" sap:quickinfo="primärer SAP-Währungscode zum ISO-Code"/>
112112
</EntityType>
113113
```
114-
We can use these SAP annotations in our UI5 view to utilize backend translations via the property `label`. Here’s an example:
114+
We can use these SAP annotations in our UI5 view to utilize backend translations via the property `label`. The metadata binding path follows this pattern:
115+
116+
```
117+
{MODEL>/#EntityType/PropertyName/@sap:annotation}
118+
```
119+
120+
- **`TRAVEL>`** — the named OData model
121+
- **`/#Currency`**`#` switches to the metadata document, `Currency` is the entity type name (from `<EntityType Name="CurrencyType">`)
122+
- **`/Currency`** — the property name within that entity type
123+
- **`/@sap:label`** — the SAP annotation attribute (here: the translated label text)
124+
125+
So `{TRAVEL>/#Currency/Currency/@sap:label}` resolves to the value of `sap:label="Währungsschlüssel"` from the metadata — displayed in the user's logon language.
126+
115127
```abap
116128
117129
DATA(tab) = page->table(

docs/development/specific/formatter.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
You can format values such as currencies, numerics, or timestamps directly in the frontend using formatter functions.
44

5+
UI5 formatter types use a special JSON-based binding syntax. The key elements:
6+
- **`parts: [...]`** — lists the model paths used as input (e.g. amount + currency)
7+
- **`type: '...'`** — the UI5 formatter type (e.g. `sap.ui.model.type.Currency`)
8+
- **`formatOptions: {...}`** — optional settings that control the output format
9+
- **`\{ ... \}`** — in ABAP string templates (`|...|`), curly braces must be escaped with `\` because `{ }` normally denotes an ABAP expression
10+
11+
The `path = abap_true` parameter on `_bind_edit` returns only the raw model path (e.g. `/XX/AMOUNT`) instead of the full binding expression (`{/XX/AMOUNT}`), so it can be embedded inside the `parts` array.
12+
13+
For example, this ABAP code:
14+
```
15+
|\{ parts: [`{ client->_bind_edit( val = amount path = abap_true ) }`], type: 'sap.ui.model.type.Currency' \}|
16+
```
17+
produces this UI5 binding string at runtime:
18+
```
19+
{ parts: ["/XX/AMOUNT", "/XX/CURRENCY"], type: 'sap.ui.model.type.Currency' }
20+
```
21+
522
```abap
623
724
CLASS z2ui5_cl_demo_app_067 DEFINITION PUBLIC.

docs/development/trouble.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22

33
#### Hide Soft Keyboard
44

5-
For UI5 input fields, the soft keyboard is automatically shown when focusing an input field. In some use cases, e.g. in the context of warehouses with small devices, this is not always wanted. To change this behavior, we have to adjust the HTML input element and switch the input type to `none`. The following snippet demonstrates how to activate/deactivate the soft keyboard:
5+
For UI5 input fields, the soft keyboard is automatically shown when focusing an input field. In some use cases, e.g. in the context of warehouses with small devices, this is not always wanted. To change this behavior, we have to adjust the HTML input element and switch the input type to `none`. The following snippet demonstrates how to activate/deactivate the soft keyboard.
66

7-
```abap
7+
This example uses the **`z2ui5.afterBE` hook** — a JavaScript callback function that the abap2UI5 frontend framework executes after every backend roundtrip. By assigning a custom function to `z2ui5.afterBE`, you can run JavaScript code in the browser after the backend has responded. This is useful for DOM manipulations that UI5 doesn't support natively.
8+
9+
The pattern works in two steps:
10+
1. **Define** the JavaScript function in a `<html:script>` tag (rendered once on init)
11+
2. **Execute** it after a backend event using `client->follow_up_action( )` with a raw JavaScript string
812

13+
```abap
914
METHOD z2ui5_if_app~main.
1015
1116
DATA input TYPE string.
1217
1318
IF client->check_on_init( ).
1419
1520
DATA(view) = z2ui5_cl_xml_view=>factory( ).
21+
22+
"Step 1: Define a JavaScript function via an inline <script> tag.
23+
"z2ui5.afterBE is a hook that runs after the backend responds.
24+
"This function takes a UI5 control ID and an inputmode value,
25+
"then modifies the HTML input element's inputmode attribute.
1626
view->_generic( name = `script`
1727
ns = `html` )->_cc_plain_xml( `z2ui5.afterBE = (id , mode) => { ` &&
1828
`var input = z2ui5.oView.byId(id).getDomRef();` &&
@@ -42,6 +52,9 @@ METHOD z2ui5_if_app~main.
4252
4353
CASE client->get( )-event.
4454
WHEN `CALL_KEYBOARD`.
55+
"Step 2: After the backend processes the event, execute the JavaScript
56+
"function as a follow-up action. This sets inputmode="none" on the
57+
"HTML element, which hides the soft keyboard on mobile devices.
4558
client->follow_up_action( `z2ui5.afterBE("ZINPUT", "none");` ).
4659
WHEN `BACK`.
4760
client->nav_app_leave( ).

0 commit comments

Comments
 (0)