Skip to Content

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

Aug 06, 2017 at 04:38 AM


avatar image
Former Member

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

    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
  // var oView = sap.ui.jsview('view.main');
    onInit: function() {
// 	onBeforeRendering: function() {

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

// 	},
// 		onExit: function() {	}
Script.js file
  var app = new sap.m.App({
		initialPage : "idViewDashboard"
 var view = sap.ui.view({
		id : "idViewDashboard",
		type : sap.ui.core.mvc.ViewType.JS

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

1 Answer

Sergio Guerrero Aug 06, 2017 at 12:27 PM

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

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)

10 |10000 characters needed characters left characters exceeded