The Use of Method createId of View
Think about when you want to display a pop-up dialog in your SAPUI5 application, normally your dialog is rendered via a fragment. And we can use function sap.ui.core.Fragment.load to load the fragment file. One of the parameters of this method is 'id. You can give any string to this parameter but make sure it is not being registered by other elements. When addressing UI5 elements on this dialog from the parent view, you have two options. The first one is getting the SAPUI5 ID from the inspector and call sap.ui.getCore().byId(). The second one is use this.getView().byId(). The difference is, for the second option, you don't need to get the ID from the inspector. Instead, you just provide the ID parameter with what you passed to the load method and what you define in your view fragment. The prerequisite of using the second option is passing a ID created by function createId() to function sap.ui.core.Fragment.load, like below:
sap.ui.core.Fragment.load({
name:"com.abc.test",
id: this.getView().createId("arDialog"),
controller:this
})
What function createId does is concatenate view ID and the given ID, as the dialog ID.
Comments
Post a Comment