来自实体列表的 Vaadin 树

Vaadin Tree from list of entities

我是 Vaadin 的新手,遇到了下一个问题。我正在尝试使用 Tree 并按某些属性分组来表示我的实体列表。一切都很好,直到第一级项目。我做了什么:

MyEntity myEntity1 = new MyEntity(1l, "prop1", "sub_prop0")
MyEntity myEntity2 = new MyEntity(2l, "prop1", "sub_prop1")
MyEntity myEntity3 = new MyEntity(3l, "prop2", "sub_prop2")

BeanContainer<Long, MyEntity > entityContainer = new BeanContainer<>(MyEntity .class);
marketContainer.setBeanIdProperty("prop"); // prop is property name for the second value in constructor
entityContainer.addBean(myEntity1);
entityContainer.addBean(myEntity2);
entityContainer.addBean(myEntity3)

Tree markets = new Tree("Markets");
markets.setContainerDataSource(entityContainer);

结果我得到了包含 2 个项目的树:prop1 和 prop2,但没有别的。实际上,我唯一需要的是让具有值的超元素形成另一个 属性 作为子项。

提前致谢。

查看找到的文档和示例 here

简而言之:

设置parent的childobject

// Set it to be a child.
tree.setParent(l2, l1);

如果不允许children,就告诉它

/* Make the moons look like leaves. */
tree.setChildrenAllowed(l2, false);

如果您希望在容器中定义层次结构,请使用实现 HierarchicalContainer 的容器之一。 您还可以使用 setParent(...) 方法来指定关系。