$(function () { pageContext.i18n.modTalk = 'moderation talk'; pageContext.i18n.replyToComment = 'Reply'; pageContext.i18n.modTalkEmpty = 'moderation talk is empty'; pageContext.url.getModTalk = "/comments/%25ID%25/listModTalk.json"; pageContext.url.possibleCommentRecipients = "/comments/%ID%/possibleRecipients.json"; pageContext.url.commentEdit = '/comments/%25ID%25/edit.html'; pageContext.url.commentView = '/comments/%ID%/view.html'; pageContext.i18n.commentVisibility = { 'full': 'Viewable by all users', 'op': 'Viewable by the original poster', 'mod': 'Viewable by moderators', 'opAndMod': 'Viewable by moderators and the original poster', 'other': 'Advanced visibility', 'dialogTitle': 'Comment visibility', 'selectGroups': 'Visible to groups', 'selectOther': 'Other recipients', 'selectOriginalPoster': 'Original poster', 'selectModerators': 'Moderators', 'selectAssignees': 'Asked to answer users' }; pageContext.i18n.commentMenuLabels = { 'comment-edit': 'comments.menu.edit', 'comment-delete': 'comments.menu.delete', 'comment-convert': 'comments.menu.convert' };pageContext.i18n.answer= { bestAnswer: 'Best Answer', controlBar : { accept: 'Accept', unaccept: 'Unaccept', acceptCommand: 'Accept this answer as correct', cancelAcceptedCommand: 'Remove this answers accepted status' } }; window.croles = { u: false, op: false, m: false, og: false, as: false, ag: false, dc: false, doc: false, eo: false, ea: false }; tools.init({ q: { e: false, ew: false, eo: false, r: false, ro: false, d: false, dow: false, fv: false, c: false, co: false, p: false, tm: false , ms: false, mos: false }, n: { f: false, vf: false, vfo: false, vr: true, vro: true, c: false, co: false, vu: false, vd: false, w: false, wo: false, l: false }, c: { e: false, eo: false, d: false, dow: false, ta: false, tao: false, l: false }, a: { e: false, ew: false, eo: false, d: false, dow: false, a: false, aoq: false, ao: false, tc: false, tco: false, p: false, tm: false }, pc: croles }, { tc: true, nsc: true }); commandUtils.initializeLabels(); }); Skip to Content

Common Controller for Parent and Nested Views

Hi, We are developing an app where we are using nested views inside main view. The main view structure is like this:

http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc">

I have two queries:

1. Is it good to use a common controller for all the views (nested and main)?

2, I want to access elements in nested views by id when I click on Buttons(Update/Reset) using this.getView().byId(). The problem is Buttons(Update/Reset) are in main view. So If I use different controller for main view and nested views, accessing elements of nested views in main view controller is not possible. So as as solution, I am trying to use common controller for all views. Will this approach work? If I use common controller, can I access nested view elements using method this.getView().byId() in common controller.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 12, 2017 at 01:42 PM

    In the main view controller use the following code:

    var subView = this.getOwnerComponent().byId("yourSubViewID");

    Then you can access elements from the subviews by using:

    var button = subView.byId("btnId");
    Add comment
    10|10000 characters needed characters exceeded

  • Jan 12, 2017 at 05:12 AM

    why u need to access the ui element?

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 12, 2017 at 06:02 AM

    Hello Vinayak,

    You still can access the main view from nested controller (I hope you would be using Routing for Navigation between the views). Try something like below:

    var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
    var oMainView = oRouter.getView("mainviewpath");  //Mention your main view path instead of 'mainviewpath'
    var oButton = oMainView.byId("oButton");

    Thank you!

    Best Regards,


    Add comment
    10|10000 characters needed characters exceeded