cancel
Showing results for 
Search instead for 
Did you mean: 

UI5: using dialog across different views

01-30-2023 12:49 PM
fabio_ubbiali Participant
2042 views 1 comments
SAP Managed Tags
Subscribe

Dear experts,

I have to decide how to design my code to use single dialog across different views.

I wrote my dialog as fragment (testfragment.xml) and I'm using SAPUI5 v.1.96.14

The following are some solutions I have explored:

1. Connect custom controller to the fragment

Following this post I tried to link the Dialog with its custom controller:

  • I have to use sap/ui/core/Fragment instead of this.loadFragment beacuse you can't connect a custom controller with the last one
  • I'm facing the following error

2. Write custom function inside a custom controller

In my project all views are extended to a BaseController that contains custom functions.

I could put all the custom functions of my dialog inside the BaseController.

3. Create the dialog via javascript instead of fragment

I could create my dialog using javascript with new sap.m.Dialog command inside BaseController.

I prefer to avoid this option because the dialog will be complex.

I am not using nested views because they are not needed with dialog.

Does anyone have any advice or other ideas?

Thanks

Fabio

Accepted Solutions (0)

Answers (1)

Answers (1)

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Likes

It seems like your error is rather related to your fragment itself.. are you able to load it at all?

The benefit of a fragment is its reusability and not needing to define the controller. So generally, every time you call the fragment from anywhere, you can define the controller as "this". All custom functions should then be loaded from the respective controller and can be redefined in other controllers.

if(this.oMsgDialog){
Fragment.load({name:"namespace.fragment.MsgDialog", controller: this})
.then(function(dialog){
this.oMsgDialog = dialog; 
this.getView().addDependent(dialog);
dialog.open();
}.bind(this));
}else{this.oMsgDialog.open();
}