Reputation: 31
I have read a number of posts regarding destroying the fragment or page to avoid duplicate ID but the problem here is that a fragment is displayed in the view page and when i press the same button again I get the error Duplicate ID.
Below is the code for fragment and controller :
<core:FragmentDefinition xmlns="sap.m"
xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
xmlns:html="http://www.w3.org/1999/xhtml" xmlns:l="sap.ui.layout">
<Page id="masterAp" showHeader="false" enableScrolling="true" >
<TileContainer
id="getTiles"
tiles="{myModel1>/0/TileCollection}">
<StandardTile
title="{myModel1>title}"
icon="{myModel1>icon}"
number="{myModel1>number}"
numberUnit="{myModel1>numberUnit}"
info="{myModel1>info}"
infoState="{myModel1>infoState}"
press="handleTilePress"/>
</TileContainer>
</Page>
</core:FragmentDefinition>
The code for controller : Please advice what line of code is missing to avoid duplicate ID error : Uncaught Error: Error: adding element with duplicate id 'getTiles'
onPressGoToMaster1 : function() {
var oDialogFragment = sap.ui.xmlfragment("yca_web111_dashboard.fragments.panel2",this.getView().getController());
var oModel = new sap.ui.model.json.JSONModel("data/dataAP.json");
sap.ui.getCore().setModel(oModel, "myModel1");
var oPage = this.getView().byId("detail");
oPage.insertContent(oDialogFragment);
this.getSplitAppObj().to(this.createId("detail"));
};
Upvotes: 0
Views: 3959
Reputation: 2353
You are trying to add the fragment every time you move to page with id: detail. Simplest solution would be to check if you have already added the fragment.
Code:
onPressGoToMaster1 : function() {
if (!this.oDialogFragment) {
this.oDialogFragment = sap.ui.xmlfragment("yca_web111_dashboard.fragments.panel2",this.getView().getController());
var oModel = new sap.ui.model.json.JSONModel("data/dataAP.json");
sap.ui.getCore().setModel(oModel, "myModel1");
var oPage = this.getView().byId("detail");
oPage.insertContent(this.oDialogFragment);
}
this.getSplitAppObj().to(this.createId("detail"));
};
Upvotes: 4