Binding BigDecimal fields to a BeanFieldGroup TextField?

Hi,

how can I bind a BigDecimal member variable to a TextField that is created in a BeanFieldGroup?


class MyBean {
	BigDecimal amount;
}


BeanFieldGroup binder = new BeanFieldGroup<MyBean>(MyBean.class);
binder.buildAndBind("Amount:", "amount");
TextField amount = (TextField) binder.getField("amount");
//how can I tell the amount field that it should be of type BigDecimal.cass?

I tried to use this one:


table.addContainerProperty("amount", BigDecimal.class, null, "Amount (USD)", null, null);

But this gives me an error:


Caused by: com.vaadin.data.Validator$InvalidValueException: Could not convert value to Number

BUT how can I set such a property when using binder?

I have the same problem here …
is it a bug ??
greatings bernhard

ps: yes i do setNullRepresentation(“”) for the field

Which Vaadin version are you using?

There was a problem with this at least with 7.0, and in 7.1 there is no generic StringToNumberConverter, but at least it should be easy to write your own StringToBigDecimalConverter as a subclass of AbstractStringToNumberConverter and set it explicitly or use a custom ConverterFactory (see the javadoc of DefaultConverterFactory).

Actually, StringToNumberConverter still exists in 7.1 (it’s removed in 7.2). It’s broken, however, along with DefaultFieldFactory which returns instances of StringToNumberConverter for any Number subclasses that don’t have a specific converter - even though it can’t possibly handle most of them. Please see
ticket #12225
.

StringToBigDecimalConverter will be added in 7.2; in the meantime, you’ll have to implement your own, like Henri said.