2012-11-12 47 views
3

我想問一下關於vaadin的UI,它是表。 如果我使用這個組件,然後我一直在使用這個命令來創建一個字段:vaadin:表中的一個字段中的多個鏈接

userTable.addContainerProperty("Status", String.class, "Active"); 

如果我想創建一個鏈接到這個領域,那麼我必須這樣做:

userTable.addContainerProperty("Action", Link.class, new Link("Remove", new ExternalResource("#"))); 

我的問題是,上面的例子中,只顯示一個字段中的單個鏈接是REMOVE鏈接。我想在該表的一個字段中創建兩個鏈接。例如,在「Action」字段下面的編輯和刪除鏈接,我該怎麼做?

回答

7

使用生成的列將組件添加到每一行。創建一個水平佈局和兩個按鈕作爲內容。 Vaadin的書更多信息的

class ValueColumnGenerator implements Table.ColumnGenerator { 
String format; /* Format string for the Double values. */ 

/** 
* Creates double value column formatter with the given 
* format string. 
*/ 
public ValueColumnGenerator(String format) { 
    this.format = format; 
} 

/** 
* Generates the cell containing the Double value. 
* The column is irrelevant in this use case. 
*/ 
public Component generateCell(Table source, Object itemId, 
           Object columnId) { 
    // Get the object stored in the cell as a property 
    Property prop = 
     source.getItem(itemId).getItemProperty(columnId); 
    if (prop.getType().equals(Double.class)) { 
     HorizontalLayout hbox = new HorizontalLayout() 
     hbox.addComponent(new Button("Status")) 
     hbox.addComponent(new Button("Remove")) 
     return hbox; 
    } 
    return null; 
} 
} 

見第5.14.5:

https://vaadin.com/book/-/page/components.table.html

+0

你可能會發現這個鏈接在實現帶按鈕的自定義單元時很有用:http://morevaadin.com/content/separation-of-concerns/ – membersound

0

您可以添加此按鈕Horizo​​ntalLayout或任何其他容器組件。然後將此佈局添加到表中的容器屬性中。

相關問題