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

混江龙づ霸主 提交于 2019-12-11 05:15:03

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7848939/how-can-i-receive-the-input-of-the-changed-fields-in-vaadin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!