on 03-09-2015 12:47 PM
Hi there,
in my application running on WAS Java 7.40 SP09 (Sapui 1.24) I discovered that message boxes are not displayed in Firefox 36.
I've tried the following:
jQuery.sap.require("sap.m.MessageBox");
sap.m.MessageBox.show("Test", {
icon : sap.m.MessageBox.Icon.ERROR,
title : "Error"
});
and also
sap.ui.commons.MessageBox.alert("Hello");
But no text box is displayed.
In Chrome/IE it works.
Is that a known issue?
Thanks in advance.
Best regards,
Thorsten.
Hi,
I've now found out that it seems only to fail if the message box should be created in a success method of a OData call:
checkTask : function(taskId) {
var oTasksODataModel = sap.ui.getCore().getModel(
"tasksODataModel");
oTasksODataModel.read("/TaskCollection('" + taskId
+ "')", null, null, true, fSuccess, fError);
function fSuccess(oEvent) {
sap.ui.commons.MessageBox.alert("Hello");
};
function fError(oEvent) {
sap.ui.commons.MessageBox.alert("Hello2");
};
}
What is the best practice to display messages in those kind of methods???
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thorsten,
Maybe you should declare both functions before the checkTask function
or
checkTask : function(taskId) {
var oTasksODataModel = sap.ui.getCore().getModel(
"tasksODataModel");
oTasksODataModel.read("/TaskCollection('" + taskId
+ "')", null, null, true, function (oEvent) {
sap.ui.commons.MessageBox.alert("Hello");
}, function (oEvent) {
sap.ui.commons.MessageBox.alert("Hello2");
}
);
}
I've now succeeded by moving the method call from the onInit() to the onBeforeRendering() method:
onBeforeRendering : function() {
var taskId = getValueOfURLParameter("taskId");
// Check if task is not processed yet
this.checkTask(taskId);
},
This is the checkTask(taskId) method:
checkTask : function(taskId) {
var oTasksODataModel = sap.ui.getCore().getModel("tasksODataModel");
oTasksODataModel.read("/TaskCollection('" + taskId
+ "')", null, null, true, fSuccess, fError);
function fSuccess(oEvent) {
console.log("Task read successfully!");
var status = oEvent.Status;
var processor = oEvent.Processor;
var user = getUser();
if (status == "COMPLETED") {
// Task has already been completed
sap.ui.commons.MessageBox.alert("Task has already been completed");
return;
}
if (status == "RESERVED") {
// Task is reserved
if (processor != "" && processor != user.toLowerCase()) {
// Processor != current user
sap.ui.commons.MessageBox.alert("Task has already been reserved by " + processor);
return;
}
}
};
}
Hi Thorsten,
What I usually do in my model is to declare a generic function that I call upon successful completion of the oData call and on other one for error.
The generic function for success looks like:
model.DataService.loadSuccess = function(data,response, dataObject) {
var resultData;
var headers;
headers = response.headers;
if(data){
if (data.results !== undefined) {
// It is a collection
resultData = data.results;
} else {
// It is not a collection
resultData = data;
}
} else {
// its a delete so no response body...
resultData = {};
}
sap.ui.getCore().getEventBus().publish("data", dataObject.serviceType, {
results : resultData,
dataObject : dataObject,
headers : headers,
response: response
});
};
As you can see this function uses the EventBus to trigger the desired action on the controller(s) having subscribed to the correct channel ("data") and correct "event" (dataObject.serviceType). It allows me to trigger actions or refresh on the desired controllers and to display the message box from within the desired controller. This works fine for me on all browsers.
The same logic is applied in the error function.
For information, here is a sample of code for the oData call itself using this generic function:
model.DataService.loadData = function(content,url,context,parameterArray,serviceId) {
var model;
var thisInstance;
thisInstance = this;
model = this.getModel(serviceId);
if (model !== null) {
// We are in an online scenario
model.read(url, context, parameterArray, true, function(data,response) {
thisInstance.loadSuccess(data,response, {
serviceType : content.serviceType,
errServiceType : content.errServiceType
});
},function(oError){
thisInstance.loadError(oError,url,{
serviceType : content.serviceType,
errServiceType : content.errServiceType
});
});
} else {
// We are in an offline scenario with mockdata
}
};
I hope this helps!
Jon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.