无法使用结构复杂的Bean使用BeanItemContainer在网格上显示数据

时间:2019-01-11 13:00:23

标签: vaadin vaadin7 vaadin-grid

非常感谢您的帮助。我开始使用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);
   }

}

0 个答案:

没有答案
相关问题