on 09-06-2012 10:54 AM
Hi guys,
we've been developing an SAP UI5 application which adheres to the MVC paradigm.
In our JS view we placed a button:
var createOrderBtn = new sap.ui.commons.Button({
text : "Create",
press : oController.onCreate
});
Now in the controller:
$.ajax({
type : "POST",
url : url,
data : formData,
contentType : "application/json; charset=utf-8",
dataType : "json",
success : createCallback
});
createCallback: function() {
alert('createCallback returned successfully');
},
This raises an exception at runtime since createCallback is not known from within the button (which is placed into the view) but it's created within the view's controller.
How can we work this out?
Thank you.
Regards
hi,
I think here is the solution which can help you.
In View:
var createOrderBtn = new sap.ui.commons.Button({ text : "Create", press : oController.onCreate });
In controller:
use this inside ajax :- success : this.createCallback
if "this.createCallback " will not work ,then you can use :-
sap.ui.controller("viewname-process.viewname").createCallback
sap.ui.controller("viewname-process.viewname") - This line you can find as 1st line in your controller.
Thanks
Gouri Shankar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sap.ui.controller("viewname-process.viewname") is still a little different from the actual controller. We cannot use sap.ui.controller("viewname-process.viewname").byId("comp_name") to get the specified controller.
In another word, sap.ui.controller("viewname-process.viewname") doesn't have the binding oView. Is it a known issue? or Do you know the reason? Thanks!
Hi Jian,
Topic is from a while ago, but I thought it might still be useful for others looking at it and facing the same issue.
When calling sap.ui.controller("controllername") a new controller object is created and thus, loosing the binding with the model / view. In order to refer to the existing controller you should pass a variable refering to the actual controller object.
E.g. when using a confirmation dialog
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",
"sap/ui/commons/MessageBox"
], function (Controller,JSONModel) {
"use strict";
return Controller.extend("my.controller.App", {
onUploadData : function(oEvent){
//Pass actual object to 'that' variable
var that = this;
//Call confirmation dialog
sap.ui.commons.MessageBox.show(
"Requesting confirmation",
sap.ui.commons.MessageBox.Icon.INFORMATION,
"Confirmation pop-up",
[sap.ui.commons.MessageBox.Action.YES, sap.ui.commons.MessageBox.Action.NO],
function(response) {
//Now use 'that' variable to execute controller function
that.execute(response);
}
);
},
execute : function(oEvent){
//Do something else
}
});
});
User | Count |
---|---|
68 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.