In this step we avoid unnecessary back-end requests by preventing the destruction of data shown in the detail area when sorting or filtering the list.
No visual change compared to the last step

You can view this step live: 🔗 Live Preview of Step 10.
You can download the solution for this step here: 📥 Download step 10 (TS)📥 Download step 10 (JS).
// webapp/controller/App.controller.ts
...
onMessageBindingChange(event: Event): void {
...
},
onSelectionChange(event: Event<{ listItem: ColumnListItem }>): void {
const listItem = event.getParameter("listItem");
this._setDetailArea(listItem.getBindingContext() as Context);
},
...
/**
* Toggles the visibility of the detail area
* @param oUserContext - the current user context
*/
_setDetailArea(userContext?: Context): void {
const detailArea = this.byId("detailArea") as Control;
const layout = this.byId("defaultLayout") as SplitterLayoutData;
const searchField = this.byId("searchField") as SearchField;
if (!detailArea) {
return; // do nothing during view destruction
}
const oldContext = detailArea.getBindingContext() as Context | null;
if (oldContext && !oldContext.isTransient()) {
oldContext.setKeepAlive(false);
}
if (userContext && !userContext.isTransient()) {
userContext.setKeepAlive(true,
// hide details if kept entity was refreshed but does not exist any more
this._setDetailArea.bind(this));
}
detailArea.setBindingContext(userContext || null);
// resize view
detailArea.setVisible(!!userContext);
layout.setSize(userContext ? "60%" : "100%");
layout.setResizable(!!userContext);
searchField.setWidth(userContext ? "40%" : "20%");
}
...
// webapp/controller/App.controller.js
...
onMessageBindingChange(event) {
...
},
onSelectionChange(event) {
const listItem = event.getParameter("listItem");
this._setDetailArea(listItem.getBindingContext());
},
...
/**
* Toggles the visibility of the detail area
* @param oUserContext - the current user context
*/
_setDetailArea(userContext) {
const detailArea = this.byId("detailArea");
const layout = this.byId("defaultLayout");
const searchField = this.byId("searchField");
if (!detailArea) {
return; // do nothing during view destruction
}
const oldContext = detailArea.getBindingContext();
if (oldContext && !oldContext.isTransient()) {
oldContext.setKeepAlive(false);
}
if (userContext && !userContext.isTransient()) {
userContext.setKeepAlive(true,
// hide details if kept entity was refreshed but does not exist any more
this._setDetailArea.bind(this));
}
detailArea.setBindingContext(userContext || null);
// resize view
detailArea.setVisible(!!userContext);
layout.setSize(userContext ? "60%" : "100%");
layout.setResizable(!!userContext);
searchField.setWidth(userContext ? "40%" : "20%");
}
...
We extend the logic of the _setDetailArea function. First, we check if there’s an “old” binding context in the detail area. If so, the keepAlive for the old context is set to false.
For the new context we set keepAlive to true and add _setDetailArea as an onBeforeDestroy function to it, which hides the detail area when the user linked to it is deleted in the back end and the list is refreshed.
You can use the Context#setKeepAlive method to prevent the destruction of information shown in the detail area when the selected user is no longer part of the list from which the information was selected. This could otherwise happen if you filter or sort the list.
Next: Step 11: Add Table with :n Navigation to Detail Area
Previous: Step 9: List-Detail Scenario
Related Information
Extending the Lifetime of a Context that is not Used Exclusively by a Table Collection