Skip to Content
0
Oct 08, 2012 at 01:02 PM

Getting a message to appear as soon as the SAPUI5 page loads

27 Views

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