this.getView().byId()
is not working as your fragment has not been provided with an Id of the view while instantiating. So, let us suppose I have a Fragment: HelloDialog.
<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core" >
<Dialog>
<content>
<List id='myId'
noDataText="No Products Found"
title="Uraian"
search="handleSearch"
confirm="handleClose"
close="handleClose"
items="{
path: 'list>/'
}" >
<StandardListItem
title="{list>Name}"
description="{list>ProductId}"
iconDensityAware="false"
iconInset="false"
type="Active" />
</List>
</content>
</Dialog>
</core:FragmentDefinition>
I will instantiate it with 2 different ways ( remember the Id of the list is :myId)
Instantiate without any Id: Code:
oDialog = sap.ui.xmlfragment("testbed.HelloDialog");
oView.addDependent(oDialog);
Now, if you will check the DOM, the Id of the List will be just myId
.
So, to fetch Id in these casem use: sap.ui.getCore().byId('myId').
Instantiate with ID: Code:
oDialog = sap.ui.xmlfragment('fragmentId', "testbed.HelloDialog");
oView.addDependent(oDialog);
Now, if you will check the DOM, the Id of the List will be : fragmentId--myId
.
Here, again you can use sap.ui.core.Fragment.byId("fragmentId", "myId");
; // Thanks to matbtt
Now, what if I associated ID of view to be used with my Fragment ie :
var oView = this.getView();
var oDialog = oView.byId("helloDialog");
// create dialog lazily
if (!oDialog) {
// create dialog via fragment factory
oDialog = sap.ui.xmlfragment(oView.getId(), "testbed.HelloDialog");
oView.addDependent(oDialog);
}
Id of List in DOM: viewId--myId
Now, I can use my this.getView().byId()
as this.getView().byId()
simply appends the view Id and then searched for the control.
P.S: You can usethis.byId()
rather than this.getView().byId()
( where this refers to the controller).