ComboBox and Converters

I’m having a hard time with ComboBox’s and Converters.
I’ve searched the forums and what I found and tried doesn’t seem to be working for me.
I’m going from Vaadin 6 to 7 and I’m not liking the Converters at all!
Vaadin 6 I had the Select class and never had to deal with Converters, it just worked.

storeCatRuleId is a BigDecimal. I added my own converter but I keep getting this error:

java.lang.ClassCastException
ERROR MESSAGE: java.math.BigDecimal cannot be cast to java.lang.String
BigDecimalToStringConvertor.convertToModel(BigDecimalToStringConvertor.java:1)

Not sure what I’m doing wrong. Any help would be appreciated.

  //ComboBox
 public StoreCategoryRuleSelect(String caption){
        setCaption(caption);
        setItemCaptionMode(ItemCaptionMode.PROPERTY);
        setItemCaptionPropertyId("storeCategoryRule");
        setFilteringMode(FilteringMode.CONTAINS);

        BeanContainer<BigDecimal, XxomMooRulesLov> dataSource = new BeanContainer<BigDecimal, XxomMooRulesLov>(XxomMooRulesLov.class);
        dataSource.setBeanIdProperty("storeCatRuleId");
        dataSource.addAll((new ArrayList<XxomMooRulesLov>()));

        this.setContainerDataSource(dataSource);              
    }

//ComboBox creation
        StoreCategoryRuleSelect storeCatRuleField = new StoreCategoryRuleSelect("Store Category");
        storeCatRuleField.setConverter((Converter)new BigDecimalToStringConvertor());
        binder.bind(storeCatRuleField, "storeCatRuleId");
        form.addComponent(storeCatRuleField);

//Converter
public class BigDecimalToStringConvertor implements Converter<String,BigDecimal> {
    
    private static final long serialVersionUID = 1921329645985949528L;

    private DecimalFormat df;

    public BigDecimalToStringConvertor() {
        df = new DecimalFormat("#0");
    }

    public BigDecimalToStringConvertor(String decimalFormatPattern) {
        df = new DecimalFormat(decimalFormatPattern);
    }

    @Override
    public BigDecimal convertToModel(String value, Class<? extends BigDecimal> targetType, Locale locale)
            throws com.vaadin.data.util.converter.Converter.ConversionException {
        
        if (value != null) {
            return new BigDecimal(value);    
        }
        
        return null;
    }

    @Override
    public String convertToPresentation(BigDecimal value, Class<? extends String> targetType, Locale locale)
            throws com.vaadin.data.util.converter.Converter.ConversionException {
        
        if (value != null) {
            return df.format(value.doubleValue());    
        }
        
        return null;
    }

    @Override
    public Class<BigDecimal> getModelType() {
        
        return BigDecimal.class;
    }

    @Override
    public Class<String> getPresentationType() {
        
        return String.class;
    }

}

Mmm, are you sure you need the converter there…? The storeCatRuleId is a BigDecimal and you have set the container’s item ID type also to be BigDecimal, so when you select something with the CB, it’s value will be BigDecimal, so there’s no need for conversion.

That’s what it looks at least with a quick look. I don’t see what would have the String type of the conversion.

Thanks for the reply!
Yeah you make a valid point which lead me to look at why I thought I needed a converter.
I was getting a CommitException that said could not convert BigDecimal to String which lead me to look at the BeanItem and the field I was committing too a String! Realized this was my issue so made changes to the BeanItem to fit my needs and now all is good of course!
Thanks a lot! Some times I just need another set of eyes to help point me down the right path!
Thanks again!