on 10-08-2012 2:02 PM
Hi All,
The example shows how to get a message to appear when a button is clicked. I'd like a message to be triggered when the page loads so that the user is greeted with the message.
I've tried the following. When the line in bold is commented in, I get a javascript error.
The button works fine though.
<script id='messageBar' type="text/javascript">
var oMessageBar = new sap.ui.commons.MessageBar('messageBar');
oMessageBar.setMaxToasted(3);
oMessageBar.setMaxListed(7);
// attach and position it to some element in the page
oMessageBar.setAnchorID("messageBarArea");
oMessageBar.setAnchorSnapPoint("begin top");
// create simple Messages
var success = new sap.ui.commons.Message("success", {type:sap.ui.commons.MessageType.Success, text:"Success short text"});
var aMeliMelos = new Array();
aMeliMelos.push(success);
//Comment the following line in and boom!.
// oMessageBar.addMessages(aMeliMelos);
// attach them to some buttons in the page
var addMeliMeloButton = new sap.ui.commons.Button("addMeliMeloButton");
addMeliMeloButton.setText("Add 3 melimelo");
addMeliMeloButton.attachPress(
function (oControlEvent) {
oMessageBar.addMessages(aMeliMelos);
}
);
addMeliMeloButton.placeAt("addMeliMelo");
</script>
</head>
<body>
<div id="messageBarArea"></div>
<table>
<tr><td id="addMeliMelo"></td></tr>
</table>
<div script="messageBar"></div>
Cheers
Richard
Hi Richard,
Change
oMessageBar.addMessages(aMeliMelos);
with
window.onload = function addMessage() {
oMessageBar.addMessages(aMeliMelos);
}
I hope this is what you meant
Regards,
R. Wuyts
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Richard,
The most easy would be to work with the MVC-paradigm and to put a welcome message in the onAfterRendering() function.
Regards,
Nicolas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.