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: java/fiori-drafts.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,6 +94,49 @@ The `DRAFT_CREATE` is an internal event that is not triggered by OData requests
94
94
95
95
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).
96
96
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
+
97
140
## Activating Drafts
98
141
99
142
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