In this tutorial we will show how to display GORM objects in Vaadin Grid.
Step 1
Create a domain object Item with two String fields name and other.
package com.vaadinongrails
class Item {
String name
String other
static constraints = {
}
}
Step 2
Create few records of Item in database in BootStrap.groovy file.
class BootStrap {
def init = { servletContext ->
new Item(name: "Hi 1", other: "There").save(failOnError: true)
new Item(name: "Hi 2", other: "There").save(failOnError: true)
new Item(name: "Hi 3", other: "There").save(failOnError: true)
new Item(name: "Hi 4", other: "There").save(failOnError: true)
}
def destroy = {
}
}
Step 3
Create instance of Grid in Vaadin code. We need to do two things to see GORM objects nicely displayed in the grid:
Create new BeanItemContainer and add GORM objects into it.
GORM object contains more fields then we have defined and we have to pick what columns will be visible. Then we have to remove the others which are not supposed to be visible.