Vaadin 网格和 Grails 域 Class
Vaadin Grid and Grails Domain Class
晚上好。我在 Vaadin 网格中显示 Grails 域对象信息时遇到问题。这是我目前所拥有的:
contenedorClientes = new BeanItemContainer<Cliente>(Cliente.class, Grails.get(ClientesService).obtenerClientes())
gdClientes = new Grid()
gdClientes.containerDataSource = contenedorClientes
基本上,我正在做的是:首先,我创建了一个 BeanItemContainer,然后我设置了这个,将这个容器配置为 Cliente 类型之一,我还设置了这个容器的数据源,在这个case 是 Grails 服务的一种方法,它 returns Cliente 类型的对象列表。
然后,我实例化一个 Vaadin 网格并将其 containerDataSource 设置为之前创建的容器。
我遇到的主要问题是网格还显示来自 Cliente 扩展的域 class 的信息。这意味着 Version、Dirty、Meta Class 等属性也会显示。我不想要这个,我只想显示我创建的域 class 中的数据。
这是域名class:
class Cliente {
String nombre
String apellido
String telefono
String email
static hasOne = [usuario:Usuario]
static constraints = {
nombre(nullable: false, blank: false)
apellido(nullable: false, blank: false)
telefono(nullable: false, blank: false, matches: '^\d{3}-\d{3}-\d{4}$', unique: true)
email(nullable: false, blank: false, email: true, unique: true)
}
}
我需要做什么才能仅显示此 class 中的信息,而不显示它派生的超级 class 中的信息?
另外,有谁知道如何设置网格中列的渲染顺序?
预先感谢您的帮助。
一般好的初读是Grid section in the Book of Vaadin。
一般方法是这样的:首先在设置容器后删除所有带有 removeAllColumns
的列,然后继续添加实际的列配置。由于您控制了此步骤,因此列的顺序自然而然(如果您真的只想重新排序 all 现有的,请使用 setColumnOrder
)。
这是该方法的独立示例:
// run with `spring run --watch vaadin.groovy`
@Grapes([
@Grab('org.vaadin.spring:spring-boot-vaadin:0.0.5.RELEASE'),
@Grab('com.vaadin:vaadin-server:7.5.10'),
@Grab('com.vaadin:vaadin-client-compiled:7.5.10'),
@Grab('com.vaadin:vaadin-themes:7.5.10'),
])
import org.vaadin.spring.annotation.VaadinUI
import com.vaadin.server.VaadinRequest
import com.vaadin.ui.*
import com.vaadin.annotations.*
import com.vaadin.data.util.*
import java.time.*
class Client {
String uuid
String name
LocalDate date
}
@VaadinUI
@Theme('valo')
class MyUI extends UI {
protected void init(VaadinRequest request) {
def clientList = (1..10).collect{
new Client(uuid: UUID.randomUUID(), name: "client #$it", date: LocalDate.now().plusDays(-it))
}
def container = new BeanItemContainer<Client>(Client, clientList)
def grid = new Grid(container)
grid.with{
setSizeFull()
// configure the columns
removeAllColumns()
[name: "Client name", date: "Start date"].each{ k,v ->
def col = addColumn(k)
col.setHeaderCaption(v)
}
}
setContent(grid)
}
}
您想在添加项目之前从容器中删除未使用的列
List<Cliente> itemsList = Cliente.listOrderById()
BeanItemContainer<Cliente> container = new BeanItemContainer<Cliente>(Cliente.class, Grails.get(ClientesService).obtenerClientes())
//remove useless columns that cause problems
def removed = ["id","errors","attached","dirty","dirtyPropertyNames","properties","metaClass","version","token"] //you get the idea
removed.each {container.removeContainerProperty(it)}
// then considering that you have removed everything you want, finally add your items ot the container
container.addAll(itemsList)
我通过使用网格的 addColumns 方法并指定我想显示的列解决了这个问题。无需删除列。
晚上好。我在 Vaadin 网格中显示 Grails 域对象信息时遇到问题。这是我目前所拥有的:
contenedorClientes = new BeanItemContainer<Cliente>(Cliente.class, Grails.get(ClientesService).obtenerClientes())
gdClientes = new Grid()
gdClientes.containerDataSource = contenedorClientes
基本上,我正在做的是:首先,我创建了一个 BeanItemContainer,然后我设置了这个,将这个容器配置为 Cliente 类型之一,我还设置了这个容器的数据源,在这个case 是 Grails 服务的一种方法,它 returns Cliente 类型的对象列表。
然后,我实例化一个 Vaadin 网格并将其 containerDataSource 设置为之前创建的容器。
我遇到的主要问题是网格还显示来自 Cliente 扩展的域 class 的信息。这意味着 Version、Dirty、Meta Class 等属性也会显示。我不想要这个,我只想显示我创建的域 class 中的数据。
这是域名class:
class Cliente {
String nombre
String apellido
String telefono
String email
static hasOne = [usuario:Usuario]
static constraints = {
nombre(nullable: false, blank: false)
apellido(nullable: false, blank: false)
telefono(nullable: false, blank: false, matches: '^\d{3}-\d{3}-\d{4}$', unique: true)
email(nullable: false, blank: false, email: true, unique: true)
}
}
我需要做什么才能仅显示此 class 中的信息,而不显示它派生的超级 class 中的信息?
另外,有谁知道如何设置网格中列的渲染顺序?
预先感谢您的帮助。
一般好的初读是Grid section in the Book of Vaadin。
一般方法是这样的:首先在设置容器后删除所有带有 removeAllColumns
的列,然后继续添加实际的列配置。由于您控制了此步骤,因此列的顺序自然而然(如果您真的只想重新排序 all 现有的,请使用 setColumnOrder
)。
这是该方法的独立示例:
// run with `spring run --watch vaadin.groovy`
@Grapes([
@Grab('org.vaadin.spring:spring-boot-vaadin:0.0.5.RELEASE'),
@Grab('com.vaadin:vaadin-server:7.5.10'),
@Grab('com.vaadin:vaadin-client-compiled:7.5.10'),
@Grab('com.vaadin:vaadin-themes:7.5.10'),
])
import org.vaadin.spring.annotation.VaadinUI
import com.vaadin.server.VaadinRequest
import com.vaadin.ui.*
import com.vaadin.annotations.*
import com.vaadin.data.util.*
import java.time.*
class Client {
String uuid
String name
LocalDate date
}
@VaadinUI
@Theme('valo')
class MyUI extends UI {
protected void init(VaadinRequest request) {
def clientList = (1..10).collect{
new Client(uuid: UUID.randomUUID(), name: "client #$it", date: LocalDate.now().plusDays(-it))
}
def container = new BeanItemContainer<Client>(Client, clientList)
def grid = new Grid(container)
grid.with{
setSizeFull()
// configure the columns
removeAllColumns()
[name: "Client name", date: "Start date"].each{ k,v ->
def col = addColumn(k)
col.setHeaderCaption(v)
}
}
setContent(grid)
}
}
您想在添加项目之前从容器中删除未使用的列
List<Cliente> itemsList = Cliente.listOrderById()
BeanItemContainer<Cliente> container = new BeanItemContainer<Cliente>(Cliente.class, Grails.get(ClientesService).obtenerClientes())
//remove useless columns that cause problems
def removed = ["id","errors","attached","dirty","dirtyPropertyNames","properties","metaClass","version","token"] //you get the idea
removed.each {container.removeContainerProperty(it)}
// then considering that you have removed everything you want, finally add your items ot the container
container.addAll(itemsList)
我通过使用网格的 addColumns 方法并指定我想显示的列解决了这个问题。无需删除列。