cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Can't instantiate a fragment after Destory it

legatimatteo
Discoverer
0 Kudos
204

Hi, I'm developing a SAPUI5 application and I need to instantiate a fragment (F) within a view (V).

The issue is that the view (V) can be closed by the user. To ensure good performance, I simply destroy it using:

V.destroyDependents();
V.destroyContent();
V.destroy();

However, the user can reopen the same view, which means I need to re-instantiate it, and with it, the fragment. I'm using this code:

Fragment.load({
    name: "webapp.fragment.DocumentaleDialog",
    id: this.createId("dialogDocumentale"),
    controller: this
}).then((oFragment) => {
    that.oDocumentaleDialog = oFragment;
    that.oView.addDependent(that.oDocumentaleDialog);
    openDocumentaleDialog();
});

The problem I'm encountering is a duplicate ID error when I try to instantiate the fragment again.

View Entire Topic
junwu
SAP Champion
SAP Champion
0 Kudos

anyway you are destroying the view, why not destroy the fragment by your code?

legatimatteo
Discoverer
0 Kudos
I'm destroying the view because it became useless 99% of the time. I'm not destroying the fragment because, reading the docs, I understood that 'destroy view implies destroy fragment.'
junwu
SAP Champion
SAP Champion
0 Kudos
apparently it seems not to be the case, why being so stubborn? just destroy the fragment
legatimatteo
Discoverer
0 Kudos
Despite following your suggestion to destroy the fragment, I'm still facing a unique ID error. I even made sure to destroy all dependents by iterating through V.getDependents() and calling oD.destroy() on each before V.destroy(). While V.getDependents() appears empty after this process, suggesting the destroy function is working, SAP seems to be holding onto these IDs in memory.
junwu
SAP Champion
SAP Champion
0 Kudos
V.getDependents(), if you debug, were you able to find the fragment? another thing is I never had the need to destroy a view. why you have to do that?