Results 1 to 7 of 7
  1. #1
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Hi Dario,
    I convert from numbers to strings, it's ok. but another error i have when i try http://localhost:8080/tutorial_demo/default.html, it show pop-up and said :

    "29: 16 : 46: 37,250 ER addfield addfield() method can only add fields that are not part of the subscription schema. Please use a value greater than 15."

    What are my fault in default.html file? Can u help me.?

  2. #2
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,090
    The tutorial demo page does not make use of "addField". I suppose you are using the StockList demo page, which does take advantage of this method in order to add "extra fields", which are computed for each update, based on the other field values. The StockList demo uses extra fields to implement the arrows and as helper fields to implement the cell colouring.
    Extra fields can be identified by names or by numbers; in the latter case, the numbers must be greater than the number of subscribed fields. Unfortunately, the StockList demo page code names the extra fields with numbers and uses the first numbers available (i.e. 14, 15 and 16). Admittedly, this is a bad choice and as soon as the number of subscribed fields is increased (which is your case), the numbers used are no longer allowed.
    So, before adding the support for your new fields in the HTML page, you should change the numbers used in the various "addField" calls; you can use 114, 115 and 116, for instance. Note that the same changes should also be made in all places in which the extra fields are used, that is inside the "formatValues" method and in some cells.

    Dario

  3. #3
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Thanks Dario, can u explain more about java script code inside default.html?

    ---- StockList demo code. File "default.html" ------

    var redColor = "#f8b87a";
    var greenColor = "lightgreen";

    function updateItem(item, updateInfo) {
    if (updateInfo == null) {
    return;
    }

    //My understand : if column pct_change has value changed, if the value > -1 show quotes_down.gif image, else show quotes_up.gif image.
    In function updateInfo.addField(16, imgDown) , i can use 114, 115, 116 like u said and changed to addField(116, imgDown). Is it correct?


    if (updateInfo.isValueChanged(3)) {
    var val = updateInfo.getNewValue(3);
    if (val.indexOf("-") > -1) {
    updateInfo.addField(16,imgDown);
    } else {
    updateInfo.addField(16,imgUp);
    }
    }

    var oldLast = updateInfo.getOldValue(1);
    var newColor;

    if (oldLast == null) { //first update for this item
    updateInfo.addField(14,greenColor,true);
    //no fade for snapshot
    if (doFade) {
    updateInfo.addField(15,"OFF",true);
    }
    } else if (updateInfo.isValueChanged(1)) {
    //at least second update
    //My understand : if column pct_change has value changed, if the new value > the old value, set color = green, else set color = red. Is it correct?
    if (oldLast > updateInfo.getNewValue(1)) {
    updateInfo.addField(14,redColor,true);
    } else {
    updateInfo.addField(14,greenColor,true);
    }
    if (doFade) {
    updateInfo.addField(15,"ON",true);
    }
    }
    }

    ---------
    function formatValues(item, itemUpdate) {
    if (itemUpdate == null) {
    return;
    }
    // itemUpdate.getServerValue(15) == "ON" --> What does it means?
    if (doFade) {
    if (itemUpdate.getServerValue(15) == "ON")
    {
    itemUpdate.setHotToColdTime(300); --> i don't understand. }
    }
    itemUpdate.setHotTime(600);

    if (itemUpdate.getServerValue(13) == "inactive") {
    carryBackUnchanged(itemUpdate); --> i don't understand here
    itemUpdate.setRowAttribute("#808080","#808080","co lor");
    } else {
    // itemUpdate.getFormattedValue(13) --> what does it means?
    if (itemUpdate.getFormattedValue(13) != null) {
    carryBackUnchanged(itemUpdate);
    itemUpdate.setRowAttribute("#000000","#000000","co lor");
    itemUpdate.setAttribute(12,"#000080","#000080","co lor");
    }

    //choose the backgroundColor
    var backC = (item % 2 == 1) ? "#eeeeee" : "#ddddee";
    var backH = itemUpdate.getServerValue(14);
    itemUpdate.setRowAttribute(backH,backC,"background Color");

    //choose the "change" field stylesheet
    var newChng;
    // i don't understand code below
    if ((newChng = itemUpdate.getFormattedValue(3)) != null) {
    var hotTxtCol = (newChng.charAt(0) == '-') ? "#dd0000" : "#009900";
    itemUpdate.setAttribute(3,"black",hotTxtCol,"color ");
    itemUpdate.setAttribute(3,"bold","bold","fontWeigh t");
    }

    itemUpdate.setAttribute(12,backC,backC,"background Color");
    }

  4. #4
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,090
    All this stuff is only for the StockList demo and may not be needed in your application.
    Let me just briefly resume the field meaning:
    • Extra field 16 is used to implement the arrow, based on the current value of "pct_change". To avoid formatting issues, we just test whether a "-" sign is present in the text value.
      The field has been associated to push cells. If you change the field to 116, you should also change
      field="16"
      into
      field="116"
      in the preceding HTML code.
    • Extra field 14 is used to set the cell background color according to the variation of "last_price". We can compute the variation only in "updateItem", so we store the color here and take it back in "formatValues" to set it on the cells.
      If you change the field to 114, you have to do it in both methods.
    • Extra field 15 is used to control cell fading, which is not enabled in the standard version of the demo (i.e. "doFade" is false). Cell fading is requested in "formatValues" through the "setHotToColdTime" method. As we want to suppress fading for the very first value, we can only get this information in "updateItem", so we store it in an extra field and take it back in "formatValues".
      If you change the field to 115, you have to do it in both methods.
    • Field 13 is the "item_status", which is used only by the JMS version of the demo Data Adapter to notify that the connection is temporarily unavailable. The page uses this information to make the cells grey in that case.
      It is not an extra field and should left it as 13, unless you add your own fields before.

    The specific way each field is formatted and shown on the demo page depends only on specific front-end requirements.

    Dario

  5. #5
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Thanks Dario, like u said : extra field 16, If I change the field to 116 :

    --- stocklist demo, default.html ----

    function updateItem(item, updateInfo) {
    if (updateInfo == null) {
    return;
    }
    if (updateInfo.isValueChanged(3)) {
    var val = updateInfo.getNewValue(3);
    if (val.indexOf("-") > -1) {
    updateInfo.addField(116,imgDown); } else {
    updateInfo.addField(116,imgUp);
    }
    }
    ...
    }

    I should also change :

    -- stocklist demo code, default.html -----

    <script>
    for (var i = 1; i <= 15; i++) {
    var suff = (i % 2 == 1) ? "A" : "B";
    document.write('<tr class="lscold'+suff+'">');
    document.write('<td nowrap style="text-align: left"><div class="stockname'+suff+'" source="lightstreamer" table="1" item="'+i+'" field="12">Loading...</div></a></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="1">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="116">-</div></td>');

    }

    </script>

    Is it correct?

    And extra field 14, if i change the field to 114, I have to do :

    ---- stock list demo code, default.html ----

    function updateItem(item, updateInfo) {
    ...
    if (oldLast == null) { //first update for this item
    updateInfo.addField(114,greenColor,true); //no fade for snapshot
    if (doFade) {
    updateInfo.addField(15,"OFF",true);
    }
    } else if (updateInfo.isValueChanged(1)) {
    //at least second update
    if (oldLast > updateInfo.getNewValue(1)) {
    updateInfo.addField(114,redColor,true);
    } else {
    updateInfo.addField(114,greenColor,true);
    }
    if (doFade) {
    updateInfo.addField(15,"ON",true);
    }
    }

    and changed :

    function formatValues(item, itemUpdate) {
    ....
    //choose the backgroundColor
    var backC = (item % 2 == 1) ? "#eeeeee" : "#ddddee";
    var backH = itemUpdate.getServerValue(114);
    itemUpdate.setRowAttribute(backH,backC,"background Color");
    }


    -----------

    Is it correct ?
    --------------------
    But in my code, i have a global variable declaration, and extra field identified by names, not by numbers, something like this :

    ////////////////Global var declaration
    var group = ["item1", "item2", "item3", "item4","item5", "item6", "item7", "item8","item9", "item10", "item11", "item12","item13", "item14", "item15", "item16", "item17", "item18", "item19", "item20", "item21", "item22", "item23", "item24", "item25", "item26", "item27", "item28", "item29", "item30"];

    var schema = ["last_price", "time", "pct_change","bid1", "bid2", "bid3", "bid1vol", "bid2vol", "bid3vol", "ask1","ask2", "ask3", "ask1vol", "ask2vol", "ask3vol", "min", "max","ref_price", "open_price", "stock_name", "ceiling", "floor", "lastVal", "lastVol", "close_price", "close_vol"];

    var newTable = new OverwriteTable(group, schema,"MERGE");

    -----

    <script>
    for (var i = 1; i <= 30; i++)
    {
    var suff = (i % 2 == 1) ? "A" : "B";

    document.write('<tr class="lscold'+suff+'">');
    document.write('<td>&nbsp;</td>');
    document.write('<td class="stockname'+suff+'"><div source="lightstreamer" table="list" item="'+i+'" field="stock_name"> - </div></td>');
    document.write('<td><div source="lightstreamer" table="list" item="'+i+'" field="ref_price"> - </div></td>');

    ...
    }
    </script>

    ---
    I can change in updateItem() function something like this?

    function updateItem(item, updateInfo) {
    if (updateInfo == null) {
    return;
    }
    if (updateInfo.isValueChanged("pct_change")) {
    var val = updateInfo.getNewValue("pct_change");

    if (val.indexOf("-") > -1)
    {
    updateInfo.addField("pct_change",imgDown); }
    else
    {
    updateInfo.addField("pct_change",imgUp);
    }
    ...
    }


    I mean I can used the name in updateItem.addField() function, not using the numbers?

  6. #6
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,090
    Yes, you can. Provided that an array is used to define the "schema", you can use names as well as numbers to identify the subscribed fields and this also holds for extra fields.

    Actually, the StockList demo front-end code is still based on the older number-based syntax and this makes it less easy to extend it. Hence, the number references to the extra fields had to be changed. Note that you should rename extra field 15 (into 115 or some custom name) as well, though it is never used with the current front-end configuration.

    Moreover, as you added your custom fields in the middle of the original field list, also the numeric references to the subscribed field numbers in the "updateItem" and "onChangingValues" method may need to be changed (if you need to preserve these event handlers at all). Moving to field-name syntax surely is the best choice.

    Dario

  7. #7
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Thanks Dario very much. I will try.

    Have a nice days.

 

 

Similar Threads

  1. Replies: 2
    Last Post: December 24th, 2010, 08:51 AM
  2. how to add the item into eventData
    By tuongkha in forum Adapter SDKs
    Replies: 9
    Last Post: January 9th, 2008, 10:51 AM

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
  •  
All times are GMT +1. The time now is 09:16 PM.