cancel
Showing results for 
Search instead for 
Did you mean: 

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

ope_prime
Explorer
0 Kudos
1,238
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.

Component.js
sap.ui.core.UIComponent.extend("sap.demo.Component",{


metadata: {
		
		routing: {
			
			config: {
				viewType: "XML",
				viewPath: "sap.demo.Views",
				targetAggregation:"pages",
				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() {
			jQuery.sap.require("sap.m.routing.RouteMatchedHandler");
			jQuery.sap.require("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);
			this._router.initialize();	
  		},
  		
  		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.
			ODataModel("proxy/http/firs-erp-dev.internal.firs.gov.ng:8000/sap/opu/odata/sap/ZTABLE1_SRV/");
  			sap.ui.getCore().setModel(oModel,"Employees");
  			oView.setModel(oModel,'Employees');
  			
  			return oView;
  					
  			
  		}
  ********************************************************		
Employee_list.controller
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);
	 oRouter.navTo('Employee',{cat:cat});		
	},
******************************************************
Employee.controller


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	
			}
	


Accepted Solutions (0)

Answers (2)

Answers (2)

ope_prime
Explorer
0 Kudos

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...

junwu
Active Contributor
0 Kudos

it has nothing to do with component.

usually we don't need to get reference to the ui control. why you need this?

junwu
Active Contributor
0 Kudos
sap.ui.getCore() think twice  before using this.

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