Announcement

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

    help using a currency formatter

    I have looked at the many examples of currency formatters in the Forums, but I have been unsuccessful in implementing the examples I have found. Below I have included the most direct approach that I am trying to use. I would appreciate a pointer to any missing elements. Also, this code is not at the launch of the application.

    If SimpleTypeFormatters need to be registered where viewPanel is obtained - please indicate that.

    Also, if the dataSource file needs to be treated as anything other than a text field in the DS.xml file - please indicate that as well. Thank you.

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

    2. FireFox 10.0.1

    3. Sample code

    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 pricingField = new DataSourceField();
    pricingField.setName("PRICINGMSRP");
    pricingField.setType(currencyType);
Working...
X