[TABLE & CONTAINER] Updated row disappear after adding a new one.


I have a strange bug who occurs with an updated row in a table.

This is my code:

		final BeanItemContainer<FraisLibreSurPosteDTO> container = new BeanItemContainer<FraisLibreSurPosteDTO>(FraisLibreSurPosteDTO.class);
		List<Object> visibleColumnIds = new ArrayList<Object>();
		table.setTableFieldFactory(new TableFieldFactory() {
			public Field createField(Container container, Object itemId,
					Object propertyId, Component uiContext) {
				if ("montantUnitaire".equals(propertyId)) {
					return new TextField();
				} else {
					return null;
		button.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				FraisLibreSurPosteDTO dto = new FraisLibreSurPosteDTO();
				dto.setCommunication("COUNT" + container.getItemIds().size());
				dto.setMontantUnitaire(new BigDecimal(container.getItemIds().size()));

So I have a table in editable mode. I also have a button who adds a new row into my table.
1 click on the button => 1 new row (screenshot 1)
No problem with that…

But if you change the value of “montantUnitaire” by for example 78 (screenshot 2) and after that you click on the button, you will see that the row with montantUnitaire = 78 is not visible!
In fact, the row is still there but the input box or the value is not visible. (screenshot 3)

I’m using the last Vaadin version (6.8.0) but I also had this problem with 6.7.6 version.

Could you help me? :bashful:

I have exactly the same problem.

One more for the same problem.

Although it does not seem to be a problem in the original post, one thing that I could imagine causing such symptoms: reusing the same TextField instance. Each cell should use a separate instance, which is not used elsewhere in the application at the same time.

If that does not help, additional information might be needed. If you can reproduce the problem in a minimal application with the code in this thread and the latest Vaadin version, please indicate so.

This is because FraisLibreSurPosteDTO (JavaBean) implements hashcode & equals methods.

Vaadin BeanItemContainer uses JavaBean as an ID that is used within hashed collections such as HashMap to associate rows with beans.

From Java we know that HashMap works fine with immutable value beans, but JavaBean is not immutable, but mutable by definition. Vaadin BeanItemContainer expects to work with JavaBean and adds additional restriction.

Form API doc:
“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”

Please, remove hashcode method from FraisLibreSurPosteDTO & all should work fine. However this is not a solution, but just an exercise to be done.

If you need hashcode & equals to compare by value and hashcode is based on standard algorithm that relays on bean’s values then use BeanContainer (not BeanItemContainer) instead.

The comment about the hashCode, that should not change during item editing was helping me a lot.

I lost one day on this but thank you Damian, it could have been more! Pff that was a tricky one!