Results 1 to 3 of 3
  1. #1
    Member
    Join Date
    Mar 2012
    Location
    Frankfurt am Main
    Posts
    7

    Property accessible from one page, but not from another

    Hi,

    I use the following page to display my SENTIMENT INDEX:

    HTML Code:
    <!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>
    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 Code:
    <!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[i]+'" field="MARKET">Loading...</div></td>');
    				document.write('<td><div source="lightstreamer" table="quotestable" item="'+quotesarr[i]+'" field="INSTRUMENT">Loading...</div></td>');
    				document.write('<td><div id="'+quotesarr[i]+'.TIME">Loading...</div></td>');
    				document.write('<td><div source="lightstreamer" table="quotestable" item="'+quotesarr[i]+'" field="BID">Loading...</div></td>');
    				document.write('<td><div source="lightstreamer" table="quotestable" item="'+quotesarr[i]+'" field="ASK">Loading...</div></td>');
    				document.write('<td><div source="lightstreamer" table="quotestable" item="'+quotesarr[i]+'" 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[i], itemUpdate.getServerValue(schema[i]));
    				}
    			}
    			function forceUnchanged(itemUpdate) {
    				for (var i = 0; i < schema.length; i++) {
    					itemUpdate.setFormattedValue(schema[i], 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>

  2. #2
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    220
    I think you missed to add the "SENTIMENT" field to your schema variable.

    The former code works because you pass null to tSchema parameter of OverwriteTable; in this case, the API looks for the name of the fields in the associated screen table. But if you specify a list of fields name only these are subscribed to the server.

    Hope this help,
    Giuseppe

  3. #3
    Member
    Join Date
    Mar 2012
    Location
    Frankfurt am Main
    Posts
    7
    You're right, the schema was the reason, many thanks for the tip!

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBulletin® Version 4.2.0
Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.
All times are GMT +1. The time now is 12:21 PM.