NativeSelect in non-editable table wrong description

Hey all, ran into an issue where I have a table which is set to editable or not based on the View Mode of the page (edit, view, create). In view mode, the whole table gets marked as non editable. This works for everything but a native select component which was pre-populated with a list of values from my DB.

My question is, how the hell can I have the table show the selected component’s description instead of it’s object’s memory address when setting the table to editable??

I’ve attached pictures of what is happening, and here is the relevant code:

private BeanContainer<UnitOfMeasure, UnitOfMeasure> uomContainer = new BeanContainer(UnitOfMeasure.class);
...
for(Persistable uom : UnitOfMeasureContainer.INSTANCE.getAll(getSession().getAttribute(Account.class).getClientID())) {
            if(((UnitOfMeasure)uom).getActive())
                uomContainer.addBean((UnitOfMeasure)uom);
        }
...

uomContainer.setBeanIdResolver(bean -> bean);

CustomFieldFactory productTableFieldFactory = new CustomFieldFactory() {
            @Override
            public Field createField(final Container container, final Object itemId, final Object propertyId, Component uiContext) {
                Field<?> field;

                if(propertyId.equals("estimatedQuantityUom") || propertyId.equals("rebateUom")) {
                    field = new NativeSelect();
                    ((NativeSelect)field).setContainerDataSource(uomContainer);
                    ((NativeSelect)field).setImmediate(true);
                    ((NativeSelect)field).setNullSelectionAllowed(false);
                    ((NativeSelect)field).setItemCaptionPropertyId("uomTypeDescription");
                    ((NativeSelect)field).setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
                    ((NativeSelect)field).addValueChangeListener(event -> {
                        FieldComparison fieldComparison = new FieldComparison(propertyId, itemId);
                        if (!productTableFields.containsKey(fieldComparison)) {
                            productTableFields.put(fieldComparison, field);
                        }
                    });
                    ((NativeSelect)field).addAttachListener(event -> {
                        FieldComparison fieldComparison = new FieldComparison(propertyId, itemId);
                        if (productTableFields.containsKey(fieldComparison)) {
                            ((NativeSelect)field).select(productTableFields.get(fieldComparison).getValue());

                        }
                    });
                    productTableGeneratedColumnFields.put(new FieldComparison(propertyId, itemId), field);
                }
                else
                    field = super.createField(container, itemId, propertyId, uiContext);


                field.setBuffered(true);
                field.addValueChangeListener(event -> {
                    if (field.isModified() && !productTableFields.containsKey(new FieldComparison(propertyId, itemId))) {
                        productTableFields.put(new FieldComparison(propertyId, itemId), field);
                    }
                });
                field.addAttachListener(event -> {
                    FieldComparison fieldComparison = new FieldComparison(propertyId, itemId);
                    if(productTableFields.containsKey(fieldComparison)) {
                        if(field instanceof TextField)
                            ((TextField) field).setValue((String) productTableFields.get(fieldComparison).getValue());
                        else if(field instanceof NativeSelect)
                            ((NativeSelect)field).select(productTableFields.get(fieldComparison).getValue());
                        else if(field instanceof CheckBox)
                            ((CheckBox)field).setValue((Boolean) productTableFields.get(fieldComparison).getValue());
                    }
                });
                return field;
            }
        };

productTable.setTableFieldFactory(productTableFieldFactory);

15605.png
15606.png

You could define a prettier toString() method for the UnitOfMeasure class than the default one. I’m not immediately sure if that’s the problem, but that’s my first guess.

That was exactly the issue. Thank you for pointing me in the right direction.