Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Formatter for currency when data source is Doubles

    SmartClient Version: SC_SNAPSHOT-2012-02-23_v8.2p/Pro Deployment (built 2012-02-23)

    2. FireFox 10.0.1

    I am looking for a currency formatter for a double. I have tried to implement the example of an inner class demonstrated here
    http://code.google.com/p/smartgwt/so...le.java?r=1547

    But I could not sort out the inheritance issue or change the datasource which is double.

    Is the SimpleTypeFormatter a better approach? Could you please point me to an example? Thank you.

    #2
    I have also attempted to implement the following use of SimpleType to create a currency formatter for a datafield, but this has no effect on display or behavior....

    final NumberFormat currencyFormat = NumberFormat.getCurrencyFormat();
    SimpleType currencyType = new SimpleType("currency", FieldType.FLOAT);
    currencyType.setNormalDisplayFormatter(new SimpleTypeFormatter() {
    @Override
    public String format(Object value, DataClass dataClass, DataBoundComponent dataBoundComponent, Record record) {
    return ("$" + currencyFormat.format(Double.valueOf(String.valueOf(value.toString()))));
    }
    });
    currencyType.setShortDisplayFormatter(new SimpleTypeFormatter() {
    @Override
    public String format(Object value, DataClass dataClass, DataBoundComponent dataBoundComponent, Record record) {
    return ("$" + currencyFormat.format(Double.valueOf(String.valueOf(value.toString()))));
    }
    });
    currencyType.setEditFormatter(new SimpleTypeFormatter() {
    @Override
    public String format(Object value, DataClass dataClass, DataBoundComponent dataBoundComponent, Record record) {
    return ("$" + currencyFormat.format(Double.valueOf(String.valueOf(value.toString()))));
    }
    });
    currencyType.setEditParser(new SimpleTypeParser() {
    @Override
    public Object parseInput(String s, DataClass dataClass, DataBoundComponent dataBoundComponent, Record record) {
    return ("$" + currencyFormat.format(Double.valueOf(String.valueOf(s))));
    }
    });
    currencyType.register();

    ------
    DataSourceField productPrice = new DatSourceField();
    productprice.setType("currencyType");

    Any suggestions on using this properly would be appreciated.

    Comment

    Working...
    X