Skip to Content
avatar image
Former Member

I want to get all methods and function from my js view to my Controller.js

Hello I have JS View and One controller. I want to import all the data from js view into controller and store it in variable. How would I do that. I tried using

1.var oView = sap.ui.jsview('view.main') in controller but didnt work. can some one guide me. By doing this i want to write a function on Button press (in a view) which can function definition in controller and displays alert message. Below is my code.

2. what is use of oninit, onAfterrndering(), onBeforeRendering() etc. I didnt get it.

Any help/guidance will be really appreciated. Thanks :)

view.js file

sap.ui.jsview('view.main',{
    
    getControllerName: function(){
        return "view.main";
    },
    
    createContent: function(oController){
        var text = new sap.m.Text({
            text:"Hello SAP, We met finally!!",
        });
        
        var button = new sap.m.Button({
            text:"Press Me",
            press: function(){
               alert("Hello, Are you SAP"); 
            }
        });
        
        return new sap.m.Page({
            // title:"{/name}",
            content:[text, button]
        });
        
    }
    
});
------------------------------------
controller.js file
sap.ui.controller('view.main',{
  // var oView = sap.ui.jsview('view.main');
    onInit: function() {
        
	},
	
// 	onBeforeRendering: function() {


// 	},
	
// 	onAfterRendering: function() {


// 	},
	
// 		onExit: function() {	}
    
});
----------------------
Script.js file
sap.ui.getCore().attachInit(function(){
  
  sap.ui.localResources("view");
  
  var app = new sap.m.App({
		initialPage : "idViewDashboard"
	});
  
 var view = sap.ui.view({
		id : "idViewDashboard",
		viewName:"view.main",
		type : sap.ui.core.mvc.ViewType.JS
	});
	
	app.addPage(view);
	app.placeAt("content");


});
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Aug 06, 2017 at 12:27 PM

    I think it would be very helpful if you read this tutorial

    https://sapui5.hana.ondemand.com/#docs/guide/3da5f4be63264db99f2e5b04c5e853db.html

    the main idea is not to get an answer right away but you should try to understand how the framework works (MVC, data models in your application, how does the view/controller work, etc)

    Add comment
    10|10000 characters needed characters exceeded