使用树网格显示XML数据

时间:2019-05-15 15:13:02

标签: vaadin vaadin8

我有一个XML数据要显示在Tree网格中。基于代码示例和学习,我设计了几个类,并尝试在Tree Grid上显示它,但屏幕上什么都没有。

以下是示例XML数据

<configadmin>
   <service id="service1">
      <property name="minutes" type="STRING" value="120"/>
      <property name="seconds" type="STRING" value="60"/>
      <property name="hours" type="STRING" value="1"/>
   </service>
   <service id="service2">
         <property name="host" type="STRING" value="localhost"/>
         <property name="port" type="STRING" value="8080"/>
   </service>
</configadmin>
  public class ConfigId {

   private String id;
   private List<ConfigProperty> configProperty = new ArrayList<>();

   public ConfigId(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 configProperty
    */
   public List<ConfigProperty> getConfigProperty() {
      return configProperty;
   }

   /**
    * @param configProperty the configProperty to set
    */
   public void setConfigProperty(List<ConfigProperty> configProperty) {
      this.configProperty = configProperty;
   }

   /**
    * @param configProperty the configProperty to add
    */
   public void addConfigProperty(ConfigProperty configProperty) {
      this.configProperty.add(configProperty);
   }

}

public class ConfigProperty{

   private String name;
   private String type;
   private String value;

   public ConfigProperty(String name, String type, String value) {
      this.name = name;
      this.type = type;
      this.value = value;
   }

   /**
    * @return the name
    */
   public String getName() {
      return name;
   }

   /**
    * @param name the name to set
    */
   public void setName(String name) {
      this.name = name;
   }

   /**
    * @return the type
    */
   public String getType() {
      return type;
   }

   /**
    * @param type the type to set
    */
   public void setType(String type) {
      this.type = type;
   }

   /**
    * @return the value
    */
   public String getValue() {
      return value;
   }

   /**
    * @param value the value to set
    */
   public void setValue(String value) {
      this.value = value;
   }

}

UI Code

      gridLayout.setSizeUndefined();
      gridLayout.setSpacing(true);
      Panel panel = new Panel("Configuration Settings");
      panel.setWidth("130px");
      TreeGrid serviceGrid = new TreeGrid();
      List<ConfigId> serviceList = xmlConfigDomParser.getServicesList();
      serviceGrid.setItems(serviceList);
      gridLayout.addComponent(panel, 0, 0);
      gridLayout.addComponent(button, 2, 0);
      gridLayout.addComponent(serviceGrid, 0, 2);


我正在尝试解决以下情况,

在单击服务ID时,需要显示所有属性,并且仅需要编辑值。

起初,我无法在树状网格上显示数据,请告知。

Service Id, Name, Type, Value
service1
        minutes, STRING, 120
        seconds, STRING, 60
        hours, STRING, 1
service2
        host, STRING, localhost
        port, STRING, 8080

0 个答案:

没有答案