2015-12-11 40 views
0

晚上好。我遇到了在Vaadin網格中顯示Grails域對象信息的問題。這是我到目前爲止有:Vaadin Grid和Grails域類

contenedorClientes = new BeanItemContainer<Cliente>(Cliente.class, Grails.get(ClientesService).obtenerClientes())  

gdClientes = new Grid() 
gdClientes.containerDataSource = contenedorClientes 

基本上,我在做什麼是這樣的:首先,我創建一個BeanItemContainer然後我設置配置這個容器的類型爲Cliente之一,我還設置了在這種情況下,這個容器的數據源是一個Grails服務的方法,它返回Cliente類型的對象列表。

然後,我實例化一個Vaadin網格,並將其containerDataSource設置爲之前創建的容器。

我遇到的主要問題是網格也顯示來自Cliente擴展的域類的信息。這意味着像Version,Dirty,Meta Class這樣的屬性也會顯示出來。我不想要這個,我只想從我創建的Domain類中顯示數據。

這裏是域類:

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) 

    } 
} 

我需要什麼,以顯示只有在這個類的信息,而不是一個在其從中導出超類呢?

另外,有沒有人知道如何設置網格中列的渲染順序?

非常感謝您的幫助。

回答

0

我解決了這個用的方法addColumns之前從容器中取出的unnused列網格並指定我想要顯示的列。無需刪除列。

0

一般良好的首讀是Grid section in the Book of Vaadin

一般的方法如下:先設置容器,然後繼續添加實際的列配置,首先刪除removeAllColumns的所有列。由於您控制此步驟,所以列的順序自然而然(如果您真的只想重新訂購全部現有,請使用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) 
    } 
} 
0

你想加入您的項目

    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)