$(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: false, vro: false, 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
0

Common Controller for Parent and Nested Views

Jan 12, 2017 at 04:46 AM

42

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Radek Chudziak Jan 12, 2017 at 01:42 PM
0

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");
Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Jan 12, 2017 at 05:12 AM
0

why u need to access the ui element?

Share
10 |10000 characters needed characters left characters exceeded
Sai Vellanki Jan 12, 2017 at 06:02 AM
0

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,

Sai.

Share
10 |10000 characters needed characters left characters exceeded