Vaadin:在表中显示一个列表 [英] Vaadin: display a list in table
问题描述
我需要显示表中列表中的所有值。
i have the need to display all values contained in a list in a table.
例如:
class Person {
String name;
String age;
List<Rule> rules;
}
我期望的结果:
|name |age |rules
alex 22 administrator, user, etc..
其中管理员和用户属于Rule.name属性
where administrator and user belong to Rule.name property
任何人都知道如何做?
推荐答案
您应该能够添加生成的列,并根据需要设置列表中的值的格式。您可以在此处找到示例,只需向下滚动到 5.16.5生成的表列
You should be able to add a generated column and format the values from the list as you need. You can find an example here, just scroll down to chapter 5.16.5 Generated Table Columns
由于您尚未发布任何代码,因此我不知道您如何设置表格。为了方便起见,我创建了一个简单的表与 BeanItemContainer< Person>
和我添加了一个规则生成列。有改进的余地,但你应该得到的想法:
Since you haven't posted any code, I don't know how you've setup your table. For convenience I have created a simple table with a BeanItemContainer<Person>
and I added a 'Rules' generated column. There's room for improvement but you should get the idea:
BeanItemContainer<Person> dataSource = new BeanItemContainer<Person>(Person.class);
table_1.setContainerDataSource(dataSource);
// create generated column and specify our "generator/formatter"
table_1.addGeneratedColumn("rules", new RuleGenerator());
dataSource.addAll(new ArrayList<Person>(){{add(new Person());}});
格式化程序/生成器:
public class RuleGenerator implements Table.ColumnGenerator {
@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
Label label = new Label();
StringBuilder labelContent = new StringBuilder();
for(Rule rule : ((Person) itemId).getRules()){
labelContent.append(rule.getName()).append(",");
}
label.setValue(labelContent.toString());
return label;
}
}
这是我得到的:
这篇关于Vaadin:在表中显示一个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!