如何在单个 table 单元格中显示多个 Vaadin 属性?

How display several Vaadin properties in a single table cell?

我有 java class 的 3 个属性需要显示 在 table 单元格中彼此下方。

这 3 个属性被添加到绑定到 table 的容器中 - 但是,这会导致每个 属性 占据不同的单元格 同一行。

e.g.
Container container = new IndexedContainer();
container.addContainerProperty("property1", String.class, "dftvalue1");
container.addContainerProperty("property2", String.class, "dftvalue2");
container.addContainerProperty("property3", String.class, "dftvalue3");

container.getContainerProperty(itemId, "property1").setValue("value1");
...
Table table = new Table("My Table");
table.setContainerDataSource(container);

我要求显示如下。


          |  property1   |
col1      |  property2   |
          |  property3   |

请问inform/advise如何做到这一点? 谢谢史蒂夫。

您将为此实施 Table.ColumnGenerator。然后创建 那里的单元格的内容。内容可以是"any" vaadin Component.

要么使用例如Label 具有 HTML 内容和 用 <br/> 连接你的道具(注意 XSS!)。或者您也可以创建一个 垂直布局并为每个 属性.

添加标签

像这样:

def c = new BeanItemContainer<SomeBean>(SomeBean)
c.addAll([
        new SomeBean(prop1: "prop11", prop2: "prop12", prop3: "prop13"),
        new SomeBean(prop1: "prop21", prop2: "prop22", prop3: "prop23"),
        new SomeBean(prop1: "prop31", prop2: "prop32", prop3: "prop33"),
])
setContent(new Table().with{
    setContainerDataSource(c, [])
    addGeneratedColumn("combined", {Table source, Object itemId, Object columnId ->
        (source.getItem(itemId) as BeanItem<SomeBean>).bean.with{
            // UNSAFE CODE! DON'T USE VERBATIM
            new Label("$it.prop1<br />$it.prop2<br />$it.prop3", ContentMode.HTML)
        }
    })
    setVisibleColumns(["combined"].toArray())
    it
})