Skip to content

Commit 704ff03

Browse files
authored
Document State Messages in Java Drafts section (#1869)
1 parent 7ed0a78 commit 704ff03

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

java/fiori-drafts.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,49 @@ The `DRAFT_CREATE` is an internal event that is not triggered by OData requests
9494

9595
For more examples, see the [Bookshop sample application](https://github.com/SAP-samples/cloud-cap-samples-java/tree/master/srv/src/main/java/my/bookshop/handlers/AdminServiceHandler.java).
9696

97+
## Validating Drafts <Beta />
98+
99+
CAP Java supports persisting (error) messages for draft-enabled entities and providing _state messages_ to the UI5 OData V4 model.
100+
This enables validations of drafts and giving feedback about errors to users faster in the UI.
101+
102+
To enable this feature, set the following properties in your `.cdsrc.json`:
103+
104+
::: code-group
105+
```json [.cdsrc.json]
106+
{
107+
"cdsc": {
108+
"beta": {
109+
"draftMessages": true
110+
}
111+
}
112+
}
113+
```
114+
:::
115+
116+
::: warning Document-based URLs
117+
The state messages feature relies on UI5 to use _document URLs_. CAP sets the annotation `@Common.AddressViaNavigationPath` to instruct UI5 to use _document URLs_. This requires UI5 version >= 1.135.0.
118+
:::
119+
120+
Setting this property adds additional elements to your draft-enabled entities and `DraftAdministrativeData`, which are required to store and serve state messages.
121+
122+
If this feature is activated, you can observe the following improvements, without any changes to the application code:
123+
124+
- Error messages for annotation-based validations (for example, `@mandatory` or `@assert...`) already appear while editing the draft.
125+
- Custom validations can now be bound to the `DRAFT_PATCH` event and can write (error) messages. It's ensured that the invalid value is still persisted, as expected by the draft choreography.
126+
- Messages no longer unexpectedly vanish from the UI after editing another field.
127+
- Messages are automatically loaded when reopening a previously edited draft.
128+
129+
By default, side-effect annotations are generated in the EDMX that instruct UI5 to fetch state messages after every `PATCH` request.
130+
In case more precise side-effect annotations are required you can disable the default side-effect annotation per entity:
131+
132+
```cds
133+
annotate MyService.MyEntity with @Common.SideEffects #alwaysFetchMessages: null;
134+
```
135+
136+
::: warning Requires Schema Update
137+
Enabling draft messages requires a database schema update, as it adds an additional element to `DraftAdministrativeData`.
138+
:::
139+
97140
## Activating Drafts
98141

99142
When you finish editing drafts by pressing the *Save* button, a draft gets activated. That means, either a single `CREATE` or `UPDATE` event is triggered to create or update the active entity with all of its compositions through a deeply structured document. You can register to these events to validate the activated data.

0 commit comments

Comments
 (0)