Grid row editor, update columns programmatically

Hi everyone,

I have a problem with Grid, i set up a container datasource and custom editors for some columns (see below)

final Grid g = new Grid();
g.setSelectionMode(SelectionMode.SINGLE);
g.setImmediate(true);

final BeanItemContainer container = new BeanItemContainer(bictRecordProdotto.class, null);
g.setContainerDataSource(container);
g.setColumnOrder(“prodotto”, “codice”, “nome”,“descrizione”,“area”,“quantita”, “prezzo”, “iva”);

final ComboBox editorProdotto = new ComboBox();
List listProdotti = parentContent.getParentView().getBUI().getBLCT_prodotto().getProdottoList(null);
BeanItemContainer prodottiContainer = new BeanItemContainer<>(BictProdotto.class, listProdotti);
editorProdotto.setContainerDataSource(prodottiContainer);
editorProdotto.setTextInputAllowed(true);
editorProdotto.setNewItemsAllowed(true);
editorProdotto.setItemCaptionMode(ItemCaptionMode.PROPERTY);
editorProdotto.setItemCaptionPropertyId(“nome”);
Column cP = g.getColumn(“prodotto”);
cP.setEditorField(editorProdotto);

When i go in grid edit mode i can update all properties of the bean with no problem after pushing “Save”.

But I’d like to change some cells values, during editing mode, after selecting a value from the comboBox “prodotto”.
I select a product from the combo and then programmatically update other columns, if needed.
I attached a listener to the editorProdotto and inside i used g.getEditedItemId(); set new values to bean but nothing change,
Seems that the UI is not sync if bean is updated in background.

Any suggestion?

Thanks,
Alessandro.

I have a similar problem, with an entity containing a formula. The grid does not refresh the new calculated value when the bean is saved with the inline editor. I have tried about everything but replacing the grid completely, which is far from a good solution…

Hi, I haven’t tried it on Grid, but with Table you have to change values in the Property of the BeanItem, not the field in the Bean (the Table and Container know nothing about when they change).

The implementation of Property for a BeanItem is (usually) a MethodProperty which implement Property.ValueChangeNotifier, so the container is informed of the change and the table update its appearence. For example to change for instance “descrizione” field you should write

beanItem.getProperty("descrizione").setValue(newValueThatYouWant); instead of

bean.setDescrizione(newValueThatYouWant); Hopefully it should be enough also for the Grid,

Cristina

Yup it works, thanks.

I just tried that, and it did not work for me. I am using Vaadin 7.6.4 currently. One difference I noticed is that I did not have a method called getProperty under beanItem, instead I had a method getItempProperty, which add a set value option. But when I attempted to set the value, the field in the grid did not reflect the value change.

I would make sense to me if I changed the value in the bean property then the value in the cell should reflect that change. Why is that not the case.