giridharkn / google-web-toolkit-doc-1-5

Automatically exported from code.google.com/p/google-web-toolkit-doc-1-5
0 stars 0 forks source link

sample code uses deprecated getValue() method on Get JSON via HTTP #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Under
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-tool
kit-doc-1-5&t=GettingStartedJSON

The sample code shows 
    stockPrices.add(new StockPrice(jsSymbol.stringValue(),
        jsPrice.getValue(),
        jsChange.getValue()));
  }

It should use doubleValue() instead

Original issue reported on code.google.com by reuben.sivan on 27 Nov 2008 at 5:00

GoogleCodeExporter commented 9 years ago
When the new tutorial (I don't have a link for it yet) is published this will 
be resolved because it uses JSNI and 
overlay types instead. The new updateTable method is as follows.

  /**
   * Update the Price and Change fields all the rows in the stock table.
   * 
   * @param prices Stock data for all rows.
   * 
   */
  private void updateTable(JsArray<StockData> prices) {
    for (int i = 0; i < prices.length(); i++) {
      updateTable(prices.get(i));
    }

    // Display timestamp showing last refresh.
    lastUpdatedLabel.setText("Last update : "
        + DateTimeFormat.getMediumDateTimeFormat().format(new Date()));

    // Clear any errors.
    errorMsgLabel.setVisible(false);

  }

  /**
   * Update a single row in the stock table.
   * 
   * @param price Stock data for a single row.
   */
  private void updateTable(StockData price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
      return;
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(
        price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
      changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
      changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);

  }

Original comment by msinclai...@gmail.com on 9 Dec 2008 at 1:37