2

I am new to SAPUI5.

I have two components/folders with views & controllers named 'view' and 'tableview'. Is it possible get 'view' context in 'tableview' ?

2
  • what do you mean by View context?Or do you mean View controller in MVC world?
    – Haojie
    Sep 12, 2014 at 12:53
  • i have multiple views.xml & controller.js files in a folder named 'view'. same way I have multiple views.xml & controller.js in a folder named 'tableview'. Now, I am loading a view(child) from 'tableview' folder with in a view(parent) which is in 'view' folder. I am wondering if there is any way for child to access parents context.
    – M_Follower
    Sep 12, 2014 at 13:35

1 Answer 1

7

If I understood correctly you are trying to access a parent controller from a child controller. Here are some proposals ordered from noob to expert ;)

  1. The simplest approach would be to just use a global variable to provide reference to the controller you need - not recommended.

  2. Give your parent view an id and call a method on it's controller like this:

    sap.ui.getCore().byId("parentViewId").getController().method();

  3. You can directly call a controllers method like this:

    sap.ui.controller("namespace.Controllername").method();

  4. I would highly recommend a more decoupled way of communication between controllers (or application components in general) using the sap.ui.core.EventBus. It implements a pattern known as Event or Message Bus and imho really rocks ;)

GL Chris

2
  • Thanks Chris. I was able to call parentview's method using sap.ui.controller("namespace.Controllername").method(); .....Is there a possibility to access parent controller's context or 'this' object in child controller ?
    – M_Follower
    Sep 13, 2014 at 6:47
  • 1
    sap.ui.controller("namespace.Controllername") gives you what you call the parent controllers context. you could also get properties from it if you like. still sth missing?
    – cschuff
    Sep 13, 2014 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.