vaadin:表中一个字段中的多个链接

Dia*_*nto 3 vaadin

我想问一下vaadin的UI,即Table.如果我使用了这个组件,那么我必须使用这个命令创建一个字段:

userTable.addContainerProperty("Status", String.class, "Active");
Run Code Online (Sandbox Code Playgroud)

如果我想创建这个字段的链接,那么我必须这样做:

userTable.addContainerProperty("Action", Link.class, new Link("Remove", new ExternalResource("#")));
Run Code Online (Sandbox Code Playgroud)

我的问题是,上面的例子,只显示一个字段中的单个链接,即REMOVE Link.我想在该表的一个字段中创建两个链接.例如,在"Action"字段下面的EDIT和DELETE链接,我该怎么做?

Dus*_*y J 7

使用生成的列将组件添加到每一行.创建水平布局和两个按钮作为内容.

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;
}
}
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅Book of Vaadin的第5.14.5节:

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