Help with a Scaladin 3.0 form

I realize that Scaladin 3.0 hasn’t yet been released, but since it is a wrapper around Vaadin, I’d hoped my use case would work.

I have a number of forms coded up much like the one from the example I’ll post below. They get NPEs when I submit them.

I’m trying to use the new FieldGroup, but I’m not using beans or any other pre-built record type. Instead, I’m just trying to map the field values to the actual fields. Yet I get an NPE when I submit this form.

What am I missing?

package code

import vaadin.scala._

class Main extends UI () {
content = new FormLayout {
val fields = new FieldGroup
val value = new TextField { caption = “Enter a value.” }
value.required = true
components += value
fields.bind(value, “value”)
components += Button(“Submit”, {
fields.commit
println(“I can’t get this to print.”)
})
}
}

Hi Nolan,

the problem with your code is that you have not set any data source for the
FieldGroup
which ultimately results in a
NullPointerException
from the
commit
method. I quickly drafted an example based on your code that uses a simple
BeanItem
as a data source.

  • Teemu
  class MyData(@BeanProperty var value: String)

  content = new FormLayout {
    val fields = new FieldGroup

    // Create a BeanItem and set it as the item data source.
    val myData = new MyData("empty")
    fields.item = new BeanItem(myData)

    val textField = new TextField { caption = "Enter a value" }
    textField.required = true
    components += textField

    // Here the textField is bound to "value" property of the item data source.
    fields.bind(textField, "value")

    components += Button("Submit", {
      fields.commit
      println("Value after commit: " + myData.getValue)
    })
  }

Cool, instead of the bean, I did this:

val fields = new FieldGroup { item = Item() }

and it seems to work. Would this be a sensible default? It seems to make the simplest case simpler