I get the error following error when trying to open a Dialog fragment a second time after calling this._oDialog.destroy()
:
Uncaught TypeError: Cannot read property 'setInitialFocusId' of null
My problem is like the problem stated here: How to clear dialog/xmlfragment content after close? However, the solution apparently just seems to be "Don't use the property setInitialFocus", which I do not use anywhere in my code.
Controller
openDialog: function() {
if (!this._oDialog) {
this._oDialog = sap.ui.xmlfragment("myFragmentPath", this);
this.getView().addDependent(this._oDialog);
}
this._oDialog.open();
},
onExit: function () {
if (this._oDialog) {
this._oDialog.destroy();
}
},
afterClose: function () {
if (this._oDialog) {
this._oDialog.destroy();
}
},
handleClose: function (oEvent) {
this._oDialog.close();
}
Dialog Fragment
<Dialog xmlns="sap.m" afterClose=".afterClose">
<!-- ... -->
</Dialog>
Main XML View
<Button press=".openDialog" />
Additional info:
- The error message occurs in the Controller line when
this._oDialog.open();
is called. - I am using the sap library version 1.60.1.
I get the error following error when trying to open a Dialog fragment a second time after calling this._oDialog.destroy()
:
Uncaught TypeError: Cannot read property 'setInitialFocusId' of null
My problem is like the problem stated here: How to clear dialog/xmlfragment content after close? However, the solution apparently just seems to be "Don't use the property setInitialFocus", which I do not use anywhere in my code.
Controller
openDialog: function() {
if (!this._oDialog) {
this._oDialog = sap.ui.xmlfragment("myFragmentPath", this);
this.getView().addDependent(this._oDialog);
}
this._oDialog.open();
},
onExit: function () {
if (this._oDialog) {
this._oDialog.destroy();
}
},
afterClose: function () {
if (this._oDialog) {
this._oDialog.destroy();
}
},
handleClose: function (oEvent) {
this._oDialog.close();
}
Dialog Fragment
<Dialog xmlns="sap.m" afterClose=".afterClose">
<!-- ... -->
</Dialog>
Main XML View
<Button press=".openDialog" />
Additional info:
- The error message occurs in the Controller line when
this._oDialog.open();
is called. - I am using the sap library version 1.60.1.
1 Answer
Reset to default 7if (this._oDialog) {
this._oDialog.destroy();
this._oDialog = null; // make it falsy so that it can be created next time
}
After close, the dialog is destroyed in your code. However, the this._oDialog
is still there.
Since this._oDialog
is not a falsy value but just a destroyed dialog instance, there is no new Dialog created in openDialog()
second time. Hence you're trying to open a destroyed dialog.
When the dialog is destroyed, its internal oPopup
is set to null, which explains the error message.
⚠️ Note
There is usually no need to destroy the dialog after closing. When the view gets destroyed, the dialog will be destroyed automatically since the fragment is dependent to the view. If the intention was to reset data values, try unbinding properties instead of destroying and recreating the entire fragment every time which is quite costly.
Since UI5 1.56, the factory function
sap.ui.xmlfragment
is deprecated because it fetches the fragment via sync XHR (blocking the main thread). Use one of the new asynchronous APIs.A simpler option is to add the fragment declaratively in your view definition with
<core:Fragment fragmentName="..." type="XML" />
to the<dependents>
aggregation of a certain control. Like in this sample.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745342322a4623384.html
评论列表(0条)