Conversion Error ComboBox

Hi everybody,
i hope there is some good boy with a lot of patience to show me how i can fix this problem.
I have a combobox within a form. The combobox take its values from a database container correctly.
But when i commit the container build to form, i recive this error

...
Caused by: com.vaadin.data.util.converter.Converter$ConversionException: Could not convert value to String

    at com.vaadin.ui.AbstractField.convertToModel(AbstractField.java:748)

    at com.vaadin.ui.AbstractField.convertToModel(AbstractField.java:725)

    at com.vaadin.ui.AbstractField.getConvertedValue(AbstractField.java:811)

    at com.vaadin.ui.AbstractField.commit(AbstractField.java:247)

    ... 41 more

Caused by: com.vaadin.data.util.converter.Converter$ConversionException: Unable to convert value of type com.vaadin.data.util.sqlcontainer.RowId to model type class java.lang.String. No converter is set and the types are not compatible.

    at com.vaadin.data.util.converter.ConverterUtil.convertToModel(ConverterUtil.java:181)

    at com.vaadin.ui.AbstractField.convertToModel(AbstractField.java:745)

    ... 44 more

I think i have to set my own Converter from String to RowId, or i wrong?
I built this one

[code]
public class StringtoRowIdConverter implements Converter<String, RowId> {

@Override

public RowId convertToModel(String value,

        Class<? extends RowId> targetType, Locale locale)

        throws com.vaadin.data.util.converter.Converter.ConversionException {

    // TODO Auto-generated method stub

    if (value == null) {

        return null;

    }

    return new RowId(value);

}

@Override

public String convertToPresentation(RowId value,

        Class<? extends String> targetType, Locale locale)

        throws com.vaadin.data.util.converter.Converter.ConversionException {

    // TODO Auto-generated method stub

    if (value == null) {

        return null;

    }

    return value.toString();

}

@Override

public Class<RowId> getModelType() {

    // TODO Auto-generated method stub

    return RowId.class;

}

@Override

public Class<String> getPresentationType() {

    // TODO Auto-generated method stub

    return String.class;

}

}
[/code]But i can’t use it because Eclipse said me
The method setConverter(Class<?>) in the type AbstractField is not applicable for the arguments (StringtoRowIdConverter)
Thank’s for help

Regards

Matteo

Cast it to Converter:

waveField.setConverter((Converter)new StringtoRowIdConverter())l

Eclipse “thinks”, that you want to use
com.vaadin.ui.AbstractField.setConverter(Class<?>)
method, so it reports it as an error.

First of all,
Thank you
very
much !!
I spent 3 days over this, without any results, and then it was Eclipse fault…
I hate it.

In the end I had to cast the Converter like Agata said and I had to invert the Converter.
From StringtoRowIdConverter() to RowIdtoStringConvert().

thanks matteo but plz if u can put the script of your solution

Hi
I fell in the same problem, solved with cast. To avoid problems like this, perhaps you should rename setConverter(Class<?>) into setConverterByFactory(Class<?>): this also clearify the different meaning.

For anyone reading Luca Pertile answer and getting confused as me (lol), please note that he’s talking to Vaadin team, not to Matteo Casagrande. It took me a while to realize what he meant by renaming
setConverter
to setConverterByFactory (“wtf?? that method doesn’t exist…”, I thought). So that’s a suggestion to the team of Vaadin framework developers to change the name of the actual method.

One thing that puzzled me out is that I’ve had to invert the order of parameters from the code Matteo posted in order for this to work. I mean: my converter became
RowIdToStringConverter
,
convertToModel()
returns a
String
and its parameters are
RowId value, Class<? extends String> targetType
and son on… How can the original code work for you??

Yes it’s true, my suggestion of renaming was (and is) for Vaadin Team.