Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Change item in BeanItemContainer

Christian Eckert
5 years ago Jun 06, 2016 10:09am
Marco Collovati
5 years ago Jun 06, 2016 10:24am
Christian Eckert
5 years ago Jun 06, 2016 10:39am
Marco Collovati
5 years ago Jun 06, 2016 11:00am
Christian Eckert
5 years ago Jun 06, 2016 11:16am
Marco Collovati
5 years ago Jun 06, 2016 12:57pm
Christian Eckert
5 years ago Jun 06, 2016 1:02pm
Marco Collovati
5 years ago Jun 06, 2016 2:26pm

Sorry, in my previous answer I wrote "equals implementation" but I meant "hashcode implementation".

If your hashcode implementation is based on the mutable field name then the BeanItemContainer could not lookup the bean from his internal itemIdToItem HashMap after modification as stated in javadocs 

BeanItemContainer uses the beans themselves as identifiers. The Object.hashCode() of a bean is used when storing and looking up beans so it must not change during the lifetime of the bean (it should not depend on any part of the bean that can be modified). Typically this restricts the implementation of Object.equals(Object) as well in order for it to fulfill the contract between equals() andhashCode().
 

If you cannot modify the hashcode implementation you should end up wiht a remove, modify and insert operation

//container.getContainerProperty(kontrakte.get(0), "name").setValue("example");
Kontrakt kontrakt = kontrakte.get(0);
int idx = container.indexOfId(kontrakt);
container.removeItem(kontrakt); kontrakt.setName("example");
container.addItemAt(idx, kontrakt); 

HTH

 

Christian Eckert
5 years ago Jun 07, 2016 7:06am
Marco Collovati
5 years ago Jun 07, 2016 7:15am

The first thing I can suppose is that your Kontract class does not have a public setter method

public void setBidqty(int qty) 
Christian Eckert
5 years ago Jun 07, 2016 7:21am
Christian Eckert
5 years ago Jun 07, 2016 7:23am
Anthony Baldarelli
4 years ago Nov 08, 2017 12:17am