На странице Найти комнату пользователи выберут комнату и дату, а затем предпримут действие onBookRoom. Действие перейдет на страницу Book Room, которая использует шаблонную страницу объекта формы ввода, а также передаст этой странице параметры DateScheduled и RoomID. Страница Book Room присвоит значения этих параметров полям DateScheduled и RoomID на странице.
Навигация сработала, параметры успешно передаются на страницу Book Room.
Мой вопрос: как я могу заполнить значения этих параметров в DateScheduled и RoomID поля на странице Book Room в SAP Fiori?
Я обыскал все справочные форумы SAP, но не нашел ответа. Есть статья, в которой описано, как предварительно заполнять поля, но она выполняется из серверной части, которая, похоже, не может получить параметры навигации.
Я использую VSCode SAP Fiori Extension и OData V4 на серверной стороне, запускаю локальную панель запуска Fiori с песочницей Fiori и NodeJS Express в качестве внешнего сервера.
Субъект, привязанный к странице Book Room, имеет следующие поля:
Код: Выделить всё
key ScheduleId,
DateScheduled,
RoomId
Код: Выделить всё
"zmrbsschedule-create": {
"semanticObject": "zmrbsschedulecreate",
"action": "create",
"title": "New Schedule",
"signature": {
"parameters": {
"DateScheduled": {
"required": false
},
"RoomId": {
"required": false
}
},
"additionalParameters": "allowed"
},
"resolutionResult": {
"applicationType": "URL",
"additionalInformation": "SAPUI5.Component=zmrbsschedulecreate",
"url": "./"
}
},
"zavailroom-display": {
"semanticObject": "zavailroom",
"action": "display",
"title": "Find Available Rooms",
"signature": { "parameters": {}, "additionalParameters": "allowed" },
"resolutionResult": {
"applicationType": "URL",
"additionalInformation": "SAPUI5.Component=zavailroom",
"url": "./"
}
},
Код: Выделить всё
sap.ui.define(['sap/ui/core/mvc/ControllerExtension'], function (ControllerExtension) {
'use strict';
return ControllerExtension.extend('zavailroom.ext.controller.ToBookRoom', {
// this section allows to extend lifecycle hooks or hooks provided by Fiori elements
override: {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf zavailroom.ext.controller.ToBookRoom
*/
onInit: function () {
// you can access the Fiori elements extensionAPI via this.base.getExtensionAPI
var oModel = this.base.getExtensionAPI().getModel();
}
},
onBookRoom: async function () {
const oAPI = this.base.getExtensionAPI();
const ctx = oAPI.getBindingContext();
const roomId = ctx.getProperty("RoomID");
const dateSche = ctx.getProperty("DateSche");
// sap.ushell.Container
const Navigation= await sap.ushell.Container.getServiceAsync("Navigation");
// trigger navigation
Navigation.navigate({
target: { semanticObject: "zmrbsschedulecreate", action: "create" },
params: {
RoomId: roomId,
DateScheduled: dateSche
}
});
}
});
CreateScheduleController.controller.js (расширение контроллера на странице Book Room)
Код: Выделить всё
sap.ui.define(['sap/ui/core/mvc/ControllerExtension'], function (ControllerExtension) {
'use strict';
return ControllerExtension.extend('zmrbsschedulecreate.ext.controller.CreateScheduleController', {
// this section allows to extend lifecycle hooks or hooks provided by Fiori elements
override: {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf zmrbsschedulecreate.ext.controller.CreateScheduleController
*/
onInit: function () {
// you can access the Fiori elements extensionAPI via this.base.getExtensionAPI
var oModel = this.base.getExtensionAPI().getModel();
},
onAfterRendering: async function () {
console.log("CreateScheduleController loaded");
const oComponent = this.getView().getController().getAppComponent();
const oParams = oComponent.getComponentData()?.startupParameters || {};
console.log("Startup parameters:", oParams);
console.log("RoomId:", oParams.RoomId);
console.log("DateScheduled:", oParams.DateScheduled);
console.log("preferredMode:", oParams.preferredMode);
var oModel = this.base.getExtensionAPI().getModel();
console.log("Model:", oModel);
const oContext = this.base.getExtensionAPI().getBindingContext();
console.log("Context:", oContext);
if (!oContext) {
console.warn("No binding context available.");
return; // no create context yet
}
// ---- SET FIELDS HERE ----
if (oParams.RoomId) {
oContext.setProperty("RoomId", oParams.RoomId[0]);
}
if (oParams.DateScheduled) {
oContext.setProperty("DateScheduled", oParams.DateScheduled[0]);
}
}
}
});
Я пытался заполнить здесь поля DateScheduled и RoomID, используя setProperty() в контексте привязки, но контекст привязки не определен. В startupParameters есть значения параметров, которые я передал из Find Room.
Это правильный путь? Или мне нужно предварительно заполнить поля где-то еще?
Подробнее здесь: https://stackoverflow.com/questions/798 ... -form-entr
Мобильная версия