1

I have an XML fragment which I have used in 2 different views. When I click on a table row for item A - view A opens and if I click on "Save" on that page - Fragment opens. Depending upon the action the user did on the Fragment (it has 2 buttons - Yes/ Cancel), next step happens but I close the fragment at the end of the process. If I click on Item B in the table - view B opens. If I click on "Save" on this page, expectation is the same fragment should open. But instead I get a duplicate ID error.

One observation: if I use a different Fragment (similar in design) in both, the controllers issue is resolved. Everything works fine. But if same, fragment error. Not sure why close if not working correctly. Tried destroy() but then it gave me setInititalFocus() undefined something like that error.

Controller A.js Similar code is in ControllerB.js

onManageConfirmation: function(oEvent) {
  var ccModelObj = {
    "headerText": "Hello",
    "operation": "deleteItem"
  };
  if (!this.ABC) {
    var ccModel = new JSONModel(); // required "sap/ui/model/json/JSONModel"
      this.ABC= sap.ui.xmlfragment("...fragments.commons.ManageConfirmation", this);
    this.getView().addDependent(this.ABC);
    this.ABC.setModel(ccModel);
  }
  this.ABC.getModel().setData(ccModelObj);
  this.ABC.open();
},

onYes: function(oEvent) {
  this.ABC.close();
},

onCancel: function(oEvent) {
// in fragment also added onClose property and calling this method only
  this.ABC.close();
},
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
THI
  • 355
  • 11
  • 40
  • 1
    About _"Tried destroy() but then it gave me setInititalFocus()"_, take a look at [“setInitialFocusId” error after _oDialog.destroy()](https://stackoverflow.com/q/54214764/5846045) – Boghyon Hoffmann Mar 27 '19 at 08:54

2 Answers2

1

Just a wild guess here, but your this is referencing two different things in your controllers.

When your in controller A everything works like a charm but then you load controller B and the check for this.ABC returns false and your code tries to load a fragment that is already at the DOM hence the duplicate Id error.

Geraldo Megale
  • 363
  • 1
  • 10
1

Have you checked your fragment.xml if you have used any ids inside of it ? If yes you must ensure to destroy the fragment before opening it again.

Francesco Iannazzo
  • 596
  • 2
  • 11
  • 31