Skip to content

Commit 36d6dd2

Browse files
committed
Document lifecycle pitfalls and public-attribute requirement
1 parent 89ab7f7 commit 36d6dd2

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

docs/cookbook/event_navigation/life_cycle.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,24 @@ ENDCLASS.
4949
```
5050

5151
See the dedicated sections of this development guide for full details on views, events, data binding, and navigation.
52+
53+
## Lifecycle Pitfalls
54+
55+
A few details of the request lifecycle are easy to miss and produce bugs that look like framework issues but are actually pattern mistakes. These are not enforced by the compiler and not reported at runtime.
56+
57+
### Bound Attributes Must Be Public
58+
`client->_bind( )` and `client->_bind_edit( )` access controller attributes from outside the class via dynamic ASSIGN. Attributes in `PROTECTED` or `PRIVATE SECTION` are invisible to the framework and silently fail to bind — the view shows nothing for one-way binding, and edits never sync back for two-way binding. There is no error.
59+
60+
Declare all attributes that participate in binding in `PUBLIC SECTION`. Helper variables that never appear in a `_bind( )` call can stay private. See [Binding → Bound Attributes Must Be Public](/cookbook/model/binding#bound-attributes-must-be-public).
61+
62+
### The View Is Only Sent When You Call `view_display`
63+
abap2UI5 does not re-render the view automatically. After an event, if you do **not** call `client->view_display( ... )` again, the frontend keeps the previous view tree and only the model data is updated from the serialized state. This is the common case — most event handlers should mutate state and return, leaving the view alone.
64+
65+
Call `view_display( )` again only when the **structure** of the view needs to change: different controls, different bindings, a new dialog, navigation to a different screen. Rebuilding and re-sending the view on every event is wasteful and can cause visible flicker, lost scroll position, and lost focus.
66+
67+
### `check_on_event` Fires Once Per Roundtrip
68+
Every HTTP request carries at most one event. `check_on_event( )` returns `abap_true` exactly once per call to `main`, for that single event. If the user clicks two buttons in quick succession, the framework dispatches them as two independent `main` invocations — they are never batched into one request.
69+
70+
Two consequences follow:
71+
- **Do not assume event ordering inside one `main`.** You cannot look at "the previous event" from within an event handler; the previous event ran in a separate request and the work process has been released since.
72+
- **State across events lives in public class attributes.** Between two events, abap2UI5 serializes the controller to the client and deserializes it on the next request. Anything stored in public attributes (and in serializable types) survives; local variables, open cursors, and acquired locks do not. For sessions that need surviving server-side resources, see [Statefulness](/cookbook/expert_more/statefulness).

docs/cookbook/model/binding.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ CLASS z2ui5_cl_app_hello_world IMPLEMENTATION.
6363
ENDCLASS.
6464
```
6565

66-
::: tip **Data in Public Attributes**
67-
With one-way or two-way binding, store your data in the public attributes of your class so the framework can read it externally. This resembles the PAI/PBO logic, where data lived in global variables.
66+
::: warning **Bound Attributes Must Be Public**
67+
`_bind( )` and `_bind_edit( )` access your class attributes from outside the controller via dynamic ASSIGN. This only works for attributes in the `PUBLIC SECTION``PROTECTED` and `PRIVATE` attributes are not visible to the framework and silently fail to bind: the view renders empty for one-way binding, and edits never sync back for two-way binding. There is no compile-time or runtime error.
68+
69+
Always declare bound data in `PUBLIC SECTION`. This resembles the PAI/PBO logic, where data lived in global variables. See also [Life Cycle → Lifecycle Pitfalls](/cookbook/event_navigation/life_cycle#lifecycle-pitfalls).
6870
:::
6971

7072
#### Known Limitations

0 commit comments

Comments
 (0)