我使用 Vaadin ListSelect 来显示选项。我将模板的标题作为显示名称,但我想从 templateContainer 中添加一个属性 (id) 来显示。我该怎么做?
ListSelect select = new ListSelect("Templates", templatesContainer);
select.setItemCaptionPropertyId("title");
最佳答案
例如:
ListSelect select = new ListSelect("Templates", templatesContainer) {
@Override
public String getItemCaption(Object itemId) {
MyTemplate t = (MyTemplate) itemId;
return t.getTitle() + "-" + t.getId();
}
};
或者如果您使用容器,则可以直接使用它:
ListSelect select = new ListSelect("Templates", templatesContainer) {
@Override
public String getItemCaption(Object itemId) {
Container c = getContainerDataSource();
String title = (String) c.getContainerProperty(itemId, "title").getValue();
Integer id = (Integer) c.getContainerProperty(itemId, "id").getValue();
return title + "-" + id;
}
};
关于java - 如何在Vaadin ListSelect中使用两个属性来显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26141957/