Hi,
I use the following page to display my SENTIMENT INDEX:
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Sentiment index</title>
<script src="LS/lscommons.js" type="text/javascript"></script>
<script src="LS/lspushpage.js" type="text/javascript"></script>
</head>
<body>
Sentiment index: <div source="lightstreamer" table="quotestable" item="SENTIMENT" field="INDEX">Loading...</div>
<script>
var page = new PushPage();
page.onEngineCreation = function(engine) {
engine.connection.setAdapterName("CFX");
engine.changeStatus("STREAMING");
}
page.bind();
page.createEngine("QuotesApp", "LS", "SHARE_SESSION");
var pushtable = new OverwriteTable(null, null, "MERGE");
// set highlighting effect when updating a cell - beginning
pushtable.onChangingValues = function(itemPos, visualUpdateInfo, itemName) {
if (visualUpdateInfo != null) {
var cold = (itemPos % 2 == 1) ? "#ffffff" : "#aaaaaa";
visualUpdateInfo.setRowAttribute("yellow", cold, "backgroundColor");
}
};
// set highlighting effect when updating a cell - end
page.addTable(pushtable, "quotestable");
</script>
</body>
</html>[/HTML]
Now, the above page works just fine, the SENTIMENT INDEX gets updated as expected. But when I use another page (see below) I only get the values for MARKET, INSTRUMENT, BID, ASK, CHANGE, but not for the SENTIMENT INDEX (it just says
Loading... all the time). The question is: am I missing something here? Why doesn't my SENTIMENT INDEX get updated correctly? Firebug didn't detect any javascript-related problems, but I guess I'm misusing Lightstreamer's Javascript API here. Would be really grateful for any hints.
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Push quotes</title>
<link rel="stylesheet" type="text/css" href="css/table.css" />
<script src="LS/lscommons.js" type="text/javascript"></script>
<script src="LS/lspushpage.js" type="text/javascript"></script>
</head>
<body>
<table cellspacing="0" cellpadding="2" border="0" >
<tr class="tableTitle">
<td class="fixed">Market</td>
<td class="fixed">Instrument</td>
<td class="fixed">Time</td>
<td class="fixed">Bid</td>
<td class="fixed">Ask</td>
<td class="fixed">Change</td>
</tr>
<script type="text/javascript">
var quotesarr = [ 'BMW', 'MERCEDES', 'DAIMLER', 'TOYOTA' ];
for (var i = 0; i < quotesarr.length; i++) {
document.write('<tr>');
document.write('<td nowrap="nowrap"><div source="lightstreamer" table="quotestable" item="'+quotesarr
+'" field="MARKET">Loading...</div></td>');
document.write('<td><div source="lightstreamer" table="quotestable" item="'+quotesarr+'" field="INSTRUMENT">Loading...</div></td>');
document.write('<td><div id="'+quotesarr+'.TIME">Loading...</div></td>');
document.write('<td><div source="lightstreamer" table="quotestable" item="'+quotesarr+'" field="BID">Loading...</div></td>');
document.write('<td><div source="lightstreamer" table="quotestable" item="'+quotesarr+'" field="ASK">Loading...</div></td>');
document.write('<td><div source="lightstreamer" table="quotestable" item="'+quotesarr+'" field="CHANGE">Loading...</div></td>');
document.write('</tr>');
}
</script>
</table>
Sentiment index: <div source="lightstreamer" table="quotestable" item="SENTIMENT" field="INDEX">Loading...</div>
<script>
var page = new PushPage();
var schema = ["MARKET", "INSTRUMENT", "BID", "ASK", "CHANGE"];
var redColor = '#ff0000';
var greenColor = '#00ff00';
var fadeout = 600;
page.onEngineCreation = function(engine) {
engine.connection.setAdapterName("CFX");
engine.changeStatus("STREAMING");
}
page.bind();
page.createEngine("QuotesApp", "LS", "SHARE_SESSION");
var pushtable = new OverwriteTable(null, schema, "MERGE");
pushtable.onItemUpdate = updateItem;
pushtable.onChangingValues = formatValues;
pushtable.setPushedHtmlEnabled(true);
page.addTable(pushtable, "quotestable");
function updateItem(item, updateInfo) {
if (updateInfo == null) {
return;
}
if (updateInfo.getNewValue("BID") == null) {
return;
}
var oldLast = updateInfo.getOldValue("BID");
if (oldLast == null) { //first update for this item
updateInfo.addField("#trend_color",greenColor,true);
} else if (updateInfo.isValueChanged("BID")) {
if (oldLast > updateInfo.getNewValue("BID")) {
updateInfo.addField("#trend_color",redColor,true);
} else {
updateInfo.addField("#trend_color",greenColor,true);
}
}
if (item != null) {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
if (minutes < 10){
minutes = "0" + minutes;
}
var timetextfield = document.getElementById(quotesarr[item-1]+'.TIME').innerHTML = hours + ":" + minutes;
}
}
function carryBackUnchanged(itemUpdate) {
for (var i = 0; i < schema.length; i++) {
itemUpdate.setFormattedValue(schema, itemUpdate.getServerValue(schema));
}
}
function forceUnchanged(itemUpdate) {
for (var i = 0; i < schema.length; i++) {
itemUpdate.setFormattedValue(schema, null);
}
}
function formatValues(item, itemUpdate) {
if (itemUpdate == null) {
return;
}
if (itemUpdate.getServerValue("BID") == null) {
forceUnchanged(itemUpdate);
return;
}
itemUpdate.setHotTime(fadeout);
if (itemUpdate.getServerValue("item_status") == "inactive") { //possible if testing the JMS version of the Data Adapter
carryBackUnchanged(itemUpdate);
} else {
if (itemUpdate.getFormattedValue("item_status") != null) { //possible if testing the JMS version of the Data Adapter
carryBackUnchanged(itemUpdate);
}
var backH = itemUpdate.getServerValue("#trend_color");
itemUpdate.setAttribute("BID",backH, null,"backgroundColor");
itemUpdate.setAttribute("ASK",backH, null,"backgroundColor");
}
}
</script>
</body>
</html>[/HTML]