gpt4 book ai didi

登录 : multiple links in one field on the table

转载 作者:行者123 更新时间:2023-12-01 10:03:35 25 4
gpt4 key购买 nike

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

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

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

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

我的问题是,上面的示例只在一个字段中显示单个链接,即 REMOVE Link。我想在该表的一个字段中创建两个链接。例如,“操作”字段下方的编辑和删除链接,我该怎么做?

最佳答案

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

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;
}
}

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

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

关于登录 : multiple links in one field on the table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13338116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com