非常感谢您的帮助。我开始使用vaadin 7-网格组件来显示来自有点复杂的bean结构的数据。我收到以下异常,但无法弄清楚如何使用addContainerProperty和addNestedContainerProperty在BeanItemContainer中定义POJO结构。 请帮助我的代码。我需要更改pojo的设计吗?
java.lang.UnsupportedOperationException: Use
addNestedContainerProperty(String) to add container properties to a
BeanItemContainer
以下是我正在尝试的代码,
ConfigProperty configPropertyA = new ConfigProperty();
configPropertyA.setProperty("SERVER1", "vm1");
configPropertyA.setProperty("db.user", "admin");
ConfigProperty configPropertyB = new ConfigProperty();
configPropertyB.setProperty("SERVER2", "vm2");
configPropertyB.setProperty("db.user", "admin1");
Service service = new Service("app.jdbc.driver");
service.addConfigProperty(configPropertyA);
service.addConfigProperty(configPropertyB);
BeanItemContainer<Service> beanItemContainer = new BeanItemContainer<Service>(Service.class);
beanItemContainer.addContainerProperty("id", Service.class, "");
beanItemContainer.addNestedContainerProperty("configPropertyList.map");
Pojos
public class Service {
/**
* @param args
*/
private String id;
private List<ConfigProperty> configPropertyList = new ArrayList<ConfigProperty>();
public Service() {
}
public Service(String id) {
this.id=id;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the configPropertyList
*/
public List<ConfigProperty> getConfigPropertyList() {
return configPropertyList;
}
/**
* @param configPropertyList the configPropertyList to set
*/
public void addConfigProperty(ConfigProperty configProperty) {
this.configPropertyList.add(configProperty);
}
}
public class ConfigProperty {
private Map<String, String> map = new HashMap<String, String>();
/*'***************************************************************************************
* Static/Inner class members
******************************************************************************************/
/*'***************************************************************************************
* Class members
******************************************************************************************/
/**
* @return the map
*/
public Map<String, String> getMap() {
return map;
}
/**
* @param map the map to set
*/
public void setProperty(String key, String value) {
this.map.put(key, value);
}
/**
* @param map the map to remove
*/
public void removeProperty(String key) {
this.map.remove(key);
}
}