cancel
Showing results for 
Search instead for 
Did you mean: 

Calling method of one view controller from another

Former Member
0 Kudos

Hi Experts,

I  have an issue and I hope some one can give a clue to resolve

In my Main UI5 page, I have 2 panel and each panel got a separate view and controller. Each panel is associated with a separate JSON Model

Now from my main UI page I have date picker and upon selection of this date I  want to transfer this date to the panel view/controller .

so in my  handledateChange : function (oEvent) {

sap.ui.controller("name space of the panel1).Panel1controllerMethod() // to pass date selected in Main page to  panel1 view/controller

--- should come here

sap.ui.controller(namespace of panel2).Panel2controllerMethod() // to pass the date selected in Main Page to panel2 view/controller

upto here is fine. Now

when inside the Panel1controllerMethod : function () {

I have reference of

this.getView.setBusy(true)

This line throws error when the method get fired .

How to change "this"  into reference of panel1.view page

}

It is more of calling a controller method from another controller . But after calling from inside the panel1 controller I am not sure how should it refer to its own panel1.view .

Any help is much appreciated

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

karthikarjun
Active Contributor
0 Kudos

Pass your main controller object to your child.

for eg:

Main controller:

*********Your Action**********

           var that = this;

          pass "That" to your child method, as an argument.

            **********Calling child***********

So now you can access your parent control and its sub classes.

Correct me if I was wrong.

Thanks,

KA

Former Member
0 Kudos

Dear all,

I manage to achieve my task through event bus instead of chaining controllers.

Thanks for all your ideas and response

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

If you have an app.controller place function in app.controller and call from any view or controller.

Regards

Former Member
0 Kudos

Thanks Sergio and rajeesh,

Please read my latest explanation above . Bascially my problem is

when the child controller method (panel1 controller) is called from the parent controller (Main controller) , inside the child controller method, how to I refer its own view --> pane1 view

SergioG_TX
Active Contributor
0 Kudos

you could set a separate js file called common or utilities and make sure it is included into your app either in the index.html file or via require... then in that file you should have functions that are common for your app, such as setting a control to busy and pass its id that way you can call it from other places. so in your controller functions you may have handleChange: function() { var id = this.getView().getId(); // get id of the view setControlBusy(id, true); // additional logic // at some point you will need to set busy false setControlBusy(id, false); } in your common.js file function setControlBusy(id, doSetBusy){   // get a handle of the control and set to busy . check syntax of getting a handle of the control   sap.ui.getById(id).setBusy(doSetBusy); }

Former Member
0 Kudos

I'm sorry if my question was understood wrongly.

when I change my date in the main page, I want to refresh both the panels in my page with the changed date selection . This is my objective .

I am passing the changed date from the main page to panel1 and panel2 pages via their respective JSON model config page (datechange - variable) . From the main page controller I

call

oConfig.setProperty("panel1_config_page with the changed date) --> Panel 1 JSON model file

oConfig.setProperty("panel2_config_page with the changed date) --> Panel 2 JSON Model file

Next

I want to refresh both Panel 1 and Panel 2 page so that it reads the JSON model file again  and re initialise the content with the changed date from the Main page

So on the main page handlechangedate : function ()  {

im calling

sap.ui.controller("namespace of panel1"). panel1. initMethod () .

this will re initialise the panel 1 page with the date passed

sap.ui.controller("namespace of panel2").panel2.initMethod()

this will re initialise the panel2 page with the date passed.

Now my problem is inside the

panel1.initMethod() {

I have a reference of panel 1 view page as

this.getView.setBusy  -- This should refer to Panel 1 view page, but  since the method is fired from Main page controller , the reference to the panel1 view page is lost .

I want to know , in this instance , how do I refer to panel1 view page .

I have other logic referencing the panel1 view page which is also throwing errors.

so I need to know , when the child controller method (panel 1 controller ) is called from parent controller (main controller) , inside the child controller method , how to I refer its own view --> panel1 view.

Thanks

Former Member
0 Kudos

Now my problem is inside the

panel1.initMethod() {

I have a reference of panel 1 view page as

this.getView.setBusy  -- This should refer to Panel 1 view page, but  since the method is fired from Main page controller , the reference to the panel1 view page is lost .

I think "this" still refers to Panel 1 View page,just do alert(this) in the init method and check it. I suspect the panel 1 view is not initialized so you are not able to get the View when you try this.getView()