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

    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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • 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)

    Add comment
    10|10000 characters needed characters exceeded