ComboBox converter

A bit of a noob question but I’m a bit stuck with converters and the ComboBox.

I have an entity like

public class Customer
… private String customerCode;

which I would like to bind to a String attribute of another bean, what would be the way to wire this up so that I could

a) use the complete Customer object in my ComboBox (it’s handy to have in the ValueChangeListener and the caption is easily derived from the instance)

b) bind just the customerCode to the String in my target instance (so that the initial Customer would also be selected by the String-binding)?

I read the reply by Roger Krüger on SO but It appeared to be more about the problem and less about a solution so now I’m confused on a higher level.

Thanks in advance,

(hoping that Christmas comes early this year and someone answers)

not sure whether I understood the problem in all entirety, but the usual approach with ComboBox is as follows:

combobox.addItem(<your Object>); combobox.setItemCaption(<your Object>, <caption>); That way you can fill ComboBox with any type of items, set the captions freely, and bind the combobox to the field which will be set to selected .

Merry Christmas! :slight_smile:

Thanks for the reply but the problem is not the display of the value, it’s using just a property of the bean as the actual value…

I think you have to rewrite your own converter like this

public class PConverter implements Converter<String, BeanP> {

    public BeanP convertToModel(String value,    Class<? extends BeanP> targetType, Locale locale)
            throws {
        for(BeanP p : EJBUtil.getListeBeanP().getItemIds()){
                return p;
        return null;

    public String convertToPresentation(BeanP value, Class<? extends String> targetType, Locale locale)
            throws {
        return value != null? value.getNom() : null; // Here select what you want to show as displayed value

    public Class<BeanP> getModelType() {
        return BeanP.class;

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


And set it as defaut converter for your combobox

        ComboBox combo = new ComboBox();
        combo.setConverter((Converter) new PConverter());