Skip to Content

Sap.ui.getCore().byId() not working with Component.js file on SAP UI5 Project

Hello guys,  Following SAP's standard with Component.js am developing an application I have built before with this concept. Am having an issue accessing a UI element from another View in a different controller. I have an Employee_list.XML view and an Employee.XML. After performing CRUD functions on Employee.XML Controller , I want to get the Table in Employee_list View and refresh before navigating. I have pasted the Component.js , and respective functions in respective controllers. Please can some help, It's annoying I have built this application successfully without Component.js and now am stalk.


metadata: {
		routing: {
			config: {
				viewType: "XML",
				viewPath: "sap.demo.Views",
				targetControl: "App",
				clearTarget: false,
				transition: "slide"
			routes: [
	         		   pattern: "",
			    	   name: "Employee_List",
			    	   view: "Employee_List",
			    	   viewType: "XML",
			    	   targetAggregation: "pages",
			    	   targetControl: "App",
	         			   pattern: "Employee/{cat}",
				    	   name: "Employee",
				    	   view: "Employee",
				    	   viewType: "XML",
				    	   targetAggregation: "pages",
				    	   targetControl: "App",	
  		init:function() {"sap.m.routing.RouteMatchedHandler");"sap.ui.core.routing.HashChanger");
			sap.ui.core.UIComponent.prototype.init.apply(this, arguments);
			this._router = this.getRouter();
			//initlialize the router
			this._routeHandler = new sap.m.routing.RouteMatchedHandler(this._router);
  		createContent:function() {
  			 var oView = sap.ui.view({
  				id: "app",
  				viewName: "sap.demo.Views.Main",
  				type: "XML",
  				viewData: {component: this}
  			var oModel = new sap.ui.model.odata.
  			return oView;
press2:function(oEvent) {
	 var Context = oEvent.getParameter("listItem");
         var path = Context.oBindingContexts.Employees.sPath;    /
	 var start = path.lastIndexOf('(') + 2;
	var Index = path.substring(start,path.length);
	var cat = Index.substring(0,3);
	var oRouter = sap.ui.core.UIComponent.getRouterFor(this);

onEmployeeBack:function() {
var oEmployeeTable = sap.ui.getCore().byId("idEmployeeTable"); //This is where my problem is...I cant access Employee table id = idEmployeeTable  in the Employee_list view	

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Jul 26, 2017 at 05:41 AM
    sap.ui.getCore() think twice  before using this.

    if you want to access ui control, why not using this.byId in your controller.

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 30, 2017 at 01:04 PM

    Hello Jun Wu , I have tried using this.byId and it didn't work .. I thought this.byId can only work for components in the same controller...

    Add comment
    10|10000 characters needed characters exceeded