Strange problem with Tables, TableFieldFactories and ComboBoxes

Hi,

I’m having a really strange problem with Tables, TableFieldFactories and ComboBoxes and I’m not really sure if I’m just doing something wrong that I’m not seeing or if there is some kind of bug in Vaadin. Below is really simplified example of code that can be used to replicate the problem. The example is written in Scala.


import scala.reflect.BeanProperty
import com.vaadin.data.Container
import com.vaadin.data.util.BeanItemContainer
import com.vaadin.ui.Component
import com.vaadin.ui.CustomComponent
import com.vaadin.ui.Field
import com.vaadin.ui.TableFieldFactory
import vaadin.scala._

case class Person(@BeanProperty var name: String) { override def toString = name }
case class TableItemTestClass(@BeanProperty var person: Person, @BeanProperty var age: Int)

/**
 * Currently tests combobox creation in table and possible bug in it
 */
class TestView extends CustomComponent {
  val personNames = "John" :: "Jane" :: "Jones" :: Nil
  val layout = new VerticalLayout
  val beanContainer: BeanItemContainer[TableItemTestClass]
 = new BeanItemContainer[TableItemTestClass]
(classOf[TableItemTestClass]
)
  val table = new Table(dataSource = beanContainer, width = 400 px, height = 250 px) {
    setTableFieldFactory(new TestTableFieldFactory)
    setVisibleColumns(Array("person", "age"))
    setColumnHeaders(Array("Person", "Age"))
  }

  val addRowButton = new Button("Add row", action = (event => new TableItemTestClass(new Person("Test" + scala.util.Random.nextInt(100)), 20)))
  val editableButton = new Button("Set table editable?", action = (event => table.setEditable(!table.isEditable)))
  val clearItems = new Button("Clear container items", action = (event => beanContainer.removeAllItems))

  class TestTableFieldFactory extends TableFieldFactory {
    override def createField(tableContainer: Container, itemId: Object, propertyId: Object, uiContext: Component): Field = {
      val row = itemId.asInstanceOf[TableItemTestClass]

      propertyId.toString match {
        case "person" => new ComboBox(nullSelectionAllowed = false) { addItem(row.person); setValue(row.person); personNames.foreach(name => addItem(new Person(name))) }
        case _ => null
      }
    }
  }

  /**
   * Initializes this view.
   */
  override def init = {
    setCompositionRoot(layout)
    layout.add(table)
    layout.add(addRowButton)
    layout.add(editableButton)
    layout.add(clearItems)
  }
}

Now, if you set the table in editable mode, add some persons in it by pressing the “Add row” button, then switch the value in the combo box to anything and press either “Add row” again or disable editable state and the row where you changed the combo box value simply “disappears”. It does still exists in the container and in the table as you can see couple of pixels thin line in it but no values are shown anymore. Why is this actually happening and what is the best way of fixing it? Current really dirty fix for this problem is to copy container values when adding new row, remove all rows from the container by calling removeAllItems() and then re-adding the copied values back to container. Any help is appreciated.