cancel
Showing results for 
Search instead for 
Did you mean: 

working with Fragment's controller

former_member185241
Active Participant
0 Kudos

Hello Folks,

I created a fragment which holds some control( table and a button in my case ). I created separate controller for Fragment.

I added the fragment to the view dynamically in onInit of the view controller.

onInit : function(){

  var f = new oFrg();

  var fc = sap.ui.xmlfragment(this.createId("f1"), "testfrg.view.test", f);

  this.getView().byId("page1").addContent(fc);

}

Now i have everything in View.

on click of button i want to do some operation to table so to get the table from fragment i have to pass id like below:

var t = sap.ui.getCore().byId("__xmlview0--f1--Table");  // f1 is fragment id and Table is table id

__xmlview0-- is getting concatenated since the event handler is in fragment own controller.

If the same event handler will be in view controller we can access table by only giving fragment id and the table id using sap.ui.core.Fragment.createId(sFragmentId, sId)

Now if i provide the id to my xmlview (lets say View1 ) then the same controller id will be concatenated with

__component0--View1--f1--Table

My question is how to get rid of __component0--View1 ?

or what is the way to get the controle of fragment into its controller.

Thanks for your input.
Abhi

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

var fc = sap.ui.xmlfragment("myFrag", "testfrg.view.test", f);

myControl = sap.ui.core.Fragment.byId("myFrag", "myControlid")

former_member185241
Active Participant
0 Kudos

Hello Jun,

Nice to see you again .

myControl = sap.ui.core.Fragment.byId("myFrag", "myControlid")

this will not give the control reference as this method will just concatenate myFrag--myControlid and try to get Id from core.


in my case control id is getting concatednated as

__xmlview0--fragmentid--controlId. ( if view id is not given)

__component0--viewid--fragmentid--controlId. ( if view id is given as viewid ).


I debugged the method


Thanks,

Abhi


junwu
Active Contributor
0 Kudos

are u sure?

core's byid will return you the control right?