Use a Simplifier Module inside an aggregation binding
-
Christopher Steinbach2 years ago #34166
Simplifier Modules are a great feature to create reusable application components. But the reusablity seems limited. In my use case I want to load the same module multiple times inside a grid with an aggregation binding. But loading modules in Simplifier is static (with process designer shapes).
Is there a method to load modules more dynamic?
Why not using a custom widget as an extension to load modules, instead of the ui designer shapes?
I thought maybe I’m not the first with this idea and someone has already developed such a widget?
Armin WinklerHas successfully completed the online course IntroductionHas successfully completed the online course Intermediate (200)Has successfully completed the online course Advanced (300)Has successfully completed the online course Basics (100)2 years ago #34168::Hi Christopher,
what you can do to achieve this behaviour is to use a ComponentContainer widget as template item for the grid’s content aggregation and bind the aggregation to some data source that will copy the template as often as is needed, i.e. if you’d use a collection variable as data source and the array contained 3 elements, the ComponentContainer would be copied 3 times as well. Subsequently, you can load the module inside all these generated ComponentContainers via script (either Script activity inside your process story or a client-side Business Object function) and optionally send data to the module via interface calls. You can extract and adapt the needed script code from the ‘Code’ section as can be found in the tab ‘Others’ in the Application Editor when you add a module setup shape to any process story and hit deploy. I will include an exemplary code snippet for you below in any case, of course you would still need to iterate over all created ComponentContainers beforehand and add their respective IDs to all lines referencing the widget ID:
var sModuleName = “myFancyModuleName”;
var cbForModuleLoad = function(data, optArg) {};var oContainer = sap.ui.getCore().byId(“MyModuleScreenId–ui_core_ComponentContainer_MyModuleContainer”);
if (!oContainer) {
console.error(“No ComponentContainer with id MyModuleScreenId–ui_core_ComponentContainer_MyModuleContainer found”);
return;
}
try {
var oOneTimeDelegate = {
onBeforeRendering: function(oEvent) {
this.Modules.addModuleContainerRelation(sModuleName, “MyModuleScreenId–ui_core_ComponentContainer_MyModuleContainer”);
this.Modules.getSubscriptionsForModule(sModuleName).forEach(function(oSub) {
sap.ui.getCore().getEventBus().subscribe(oSub.channel, oSub.event, oSub.listener, this);
}.bind(this));cbForModuleLoad.call(this, oEvent);
oContainer.removeEventDelegate(oOneTimeDelegate);// publish to module interfaces if needed
var dataFormyFancyModuleName_myModuleInterfaceName = {};
dataFormyFancyModuleName_myModuleInterfaceName[‘myModuleInterfaceParameterName’] = “myModuleInterfaceParameterValue”;
sap.ui.getCore().getEventBus().publish(“AppTomyFancyModuleName”, “myModuleInterfaceName”, dataFormyFancyModuleName_myModuleInterfaceName);}.bind(this)
};oContainer.addEventDelegate(oOneTimeDelegate);
this.Modules.getDependenciesForModule(sModuleName).forEach(function(oDep) {
jQuery.sap.registerModulePath(oDep.name, oDep.url);
});
oContainer.setSettings({
componentData: {
loadedBy: this.getApplicationName()
}
});
oContainer.setUrl(SimplifierSettings.getModulePath(sModuleName));
oContainer.setName(sModuleName);} catch (e) {
console.error(e.toString());
}Hope this helps. Kind regards,
Armin
You must be logged in to reply to this topic.