如何在Vaadin中接收更改字段的输入? [英] How can I receive the input of the changed fields in Vaadin?
问题描述
我的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?
推荐答案
Vaadin不会跟踪容器中的已修改项。您必须跟踪bean(人
)中的修改。对于所有可编辑属性,并在发生更改时设置修改标志。在保存按钮侦听器中,您可以过滤掉所有修改后的项目。
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.
这篇关于如何在Vaadin中接收更改字段的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!