Skip to content

Commit 7329a9f

Browse files
committed
Split Controller page into Life Cycle, Init, Event, Navigated submenu
1 parent 857ebac commit 7329a9f

8 files changed

Lines changed: 172 additions & 93 deletions

File tree

docs/.vitepress/config.mjs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default defineConfig({
6060
text: "Guide",
6161
items: [
6262
{ text: "Introduction", link: "/get_started/about" },
63-
{ text: "Cookbook", link: "/development/general" },
63+
{ text: "Cookbook", link: "/development/controller/controller" },
6464
{ text: "Configuration", link: "/configuration/setup" },
6565
{ text: "Advanced Topic", link: "/advanced/downporting" },
6666
{ text: "Technical Insight", link: "/technical/concept" },
@@ -114,10 +114,20 @@ export default defineConfig({
114114
},
115115
{
116116
text: "Cookbook",
117-
link: "/development/general",
117+
link: "/development/controller/controller",
118118
collapsed: true,
119119
items: [
120-
{ text: "Controller", link: "/development/general" },
120+
{
121+
text: "Controller",
122+
link: "/development/controller/controller",
123+
collapsed: true,
124+
items: [
125+
{ text: "Life Cycle", link: "/development/controller/life_cycle" },
126+
{ text: "Init", link: "/development/controller/init" },
127+
{ text: "Event", link: "/development/controller/event" },
128+
{ text: "Navigated", link: "/development/controller/navigated" },
129+
],
130+
},
121131
{
122132
text: "View",
123133
collapsed: true,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
outline: [2, 4]
3+
---
4+
# Controller
5+
6+
abap2UI5 gives you great flexibility in how you structure apps. Most sample apps follow the pattern below. Use it as a starting point, and tweak it or build a wrapper around abap2UI5 for more specific behavior.
7+
8+
The idea: every request enters the `main` method, and you use `CASE` to dispatch between initialization, navigation returns, and user events.
9+
10+
The following sections walk through each phase:
11+
12+
- [Life Cycle](/development/controller/life_cycle) — the overall dispatch pattern in `main`
13+
- [Init](/development/controller/init) — first-time setup and rendering the view
14+
- [Event](/development/controller/event) — handling user actions
15+
- [Navigated](/development/controller/navigated) — returning from another app
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
outline: [2, 4]
3+
---
4+
# Event
5+
6+
`client->check_on_event` returns `abap_true` when the request was triggered by a user event. Read the event name with `client->get( )-event` and dispatch to the matching handler.
7+
8+
```abap
9+
METHOD z2ui5_if_app~main.
10+
11+
me->client = client.
12+
CASE abap_true.
13+
WHEN client->check_on_event( ).
14+
on_event( ).
15+
ENDCASE.
16+
17+
ENDMETHOD.
18+
19+
METHOD on_event.
20+
21+
DATA(lt_arg) = client->get_event_arg( ).
22+
23+
CASE client->get( )-event.
24+
WHEN `BUTTON_POST`.
25+
client->message_toast_display( |{ mv_value } - send to the server| ).
26+
ENDCASE.
27+
28+
ENDMETHOD.
29+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
outline: [2, 4]
3+
---
4+
# Init
5+
6+
`client->check_on_init` returns `abap_true` on the first request. Use this branch to initialize app data and render the initial view.
7+
8+
```abap
9+
METHOD z2ui5_if_app~main.
10+
11+
me->client = client.
12+
CASE abap_true.
13+
WHEN client->check_on_init( ).
14+
on_init( ).
15+
display_view( ).
16+
ENDCASE.
17+
18+
ENDMETHOD.
19+
20+
METHOD on_init.
21+
22+
mv_value = `value`.
23+
24+
ENDMETHOD.
25+
26+
METHOD display_view.
27+
28+
DATA(view) = z2ui5_cl_xml_view=>factory( ).
29+
view->shell( )->page(
30+
)->simple_form( title = `Form Title` editable = abap_true
31+
)->content( `form`
32+
)->title( `Input`
33+
)->label( `value`
34+
)->input( client->_bind_edit( mv_value )
35+
)->button(
36+
text = `post`
37+
press = client->_event( `BUTTON_POST` ) ).
38+
client->view_display( view->stringify( ) ).
39+
40+
ENDMETHOD.
41+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
outline: [2, 4]
3+
---
4+
# Life Cycle
5+
6+
Every request to an abap2UI5 app enters the `main` method. The recommended pattern uses `CASE abap_true` together with `client->check_on_init`, `client->check_on_event`, and `client->check_on_navigated` to dispatch to the matching handler method.
7+
8+
```abap
9+
CLASS z2ui5_cl_demo_app_001 DEFINITION PUBLIC.
10+
11+
PUBLIC SECTION.
12+
13+
INTERFACES z2ui5_if_app.
14+
15+
DATA mv_value TYPE string.
16+
17+
PROTECTED SECTION.
18+
19+
DATA client TYPE REF TO z2ui5_if_client.
20+
21+
METHODS on_init.
22+
METHODS display_view.
23+
METHODS on_event.
24+
METHODS on_navigated.
25+
26+
PRIVATE SECTION.
27+
ENDCLASS.
28+
29+
CLASS z2ui5_cl_demo_app_001 IMPLEMENTATION.
30+
31+
METHOD z2ui5_if_app~main.
32+
33+
me->client = client.
34+
CASE abap_true.
35+
WHEN client->check_on_init( ).
36+
on_init( ).
37+
display_view( ).
38+
WHEN client->check_on_event( ).
39+
on_event( ).
40+
WHEN client->check_on_navigated( ).
41+
on_navigated( ).
42+
ENDCASE.
43+
44+
ENDMETHOD.
45+
46+
ENDCLASS.
47+
```
48+
49+
See the dedicated sections of this development guide for full details on views, events, data binding, and navigation.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
outline: [2, 4]
3+
---
4+
# Navigated
5+
6+
`client->check_on_navigated` returns `abap_true` when the user returns from another app. Use `client->get_app_prev` to access the previous app instance and read any data it returns.
7+
8+
```abap
9+
METHOD z2ui5_if_app~main.
10+
11+
me->client = client.
12+
CASE abap_true.
13+
WHEN client->check_on_navigated( ).
14+
on_navigated( ).
15+
ENDCASE.
16+
17+
ENDMETHOD.
18+
19+
METHOD on_navigated.
20+
21+
DATA(lo_app_prev) = client->get_app_prev( ).
22+
23+
ENDMETHOD.
24+
```

docs/development/general.md

Lines changed: 0 additions & 89 deletions
This file was deleted.

docs/get_started/next.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ outline: [2, 4]
66
With abap2UI5 up and running, here are a few directions to take.
77

88
#### Development
9-
Learn how to build views, handle events, share data, and work with tables. The development guide covers what you need for everyday work. Start with the [Development guide](/development/general).
9+
Learn how to build views, handle events, share data, and work with tables. The development guide covers what you need for everyday work. Start with the [Development guide](/development/controller/controller).
1010

1111
#### Configuration
1212
Getting ready for production? The configuration guides walk through security, performance tuning, Launchpad integration, and more. Start with the [Configuration guide](/configuration/setup).

0 commit comments

Comments
 (0)