Twistleton Twistleton - 4 days ago 6
Scala Question

How can I receive the input of the changed fields in Vaadin?

My Vaadin application provides a little table, which is editable.

If the user - after changing some fields - clicks on the save button, I will receive all the rows and save the changed rows into the database.

// create a bean item container
val writers: BeanItemContainer[Person] = new BeanItemContainer[Person](classOf[Person])

// create some person objects
writers.addBean(new Person("Thomas", "Mann", 1929))
writers.addBean(new Person("W. B.", "Yeats", 1923))
writers.addBean(new Person("G√ľnter", "Grass", 1999))

// create the table incl. the bean item container
val table: Table = new Table("Nobel Prize for Literature", writers)

// set some options for the table
table.setImmediate(true)
table.setEditable(true)
table.setValidationVisible(true)

// create the save button
val saveButton = new Button("save")

// create a table listener
saveButton.addListener(new Button.ClickListener() {
def buttonClick(event: com.vaadin.ui.Button#ClickEvent) {
table.commit()
val writerList = table.getItemIds.asInstanceOf[Collection[Person]].asScala.toList
//
// **THIS WILL NOT WORK**
//
// I received always the original rows, without the
// user input, but I needs the user input, the changed rows.
//
//
for (item <- writerList) {
println("firstName ====> " + item.getFirstName)
println("lastName =====> " + item.getLastName)
println("year==========> " + item.getYear)
}
}
});


How can I receive the changed rows with the user input? Is it necessary to implement a form? If yes, how I can implement a form in this case?

Answer

Vaadin does not keep track of modified items in a container. You have to track the modifications in your beans (Person). Define setters for all editable properties and set a modified flag if something changes. In the save button listener you can filter out all modified items.

Comments