Vaadin 使用树形网格显示XML数据
我有一个XML数据要显示在树形网格中。基于代码示例和学习,我设计了几个类,并尝试将其显示在树形网格上,但屏幕上没有显示任何内容 下面是示例XML数据Vaadin 使用树形网格显示XML数据,vaadin,vaadin8,Vaadin,Vaadin8,我有一个XML数据要显示在树形网格中。基于代码示例和学习,我设计了几个类,并尝试将其显示在树形网格上,但屏幕上没有显示任何内容 下面是示例XML数据 <configadmin> <service id="service1"> <property name="minutes" type="STRING" value="120"/> <property name="seconds" type="STRING" value="60
<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>
看起来您还没有向树网格添加任何列:)您可以查看addColumn方法,或者使用
新的TreeGrid(ConfigId.class)代码>自动生成。我更新了代码,现在我至少可以得到一些显示,即使结果不是预期的TreeGrid serviceGrid=新的TreeGrid(ConfigId.class);我得到的结果如下所示,ConfigProperty Id calibration.instance.storage[config.util。ConfigProperty@2b93bdff,config.util。ConfigProperty@3340c66d,config.util。ConfigProperty@67d10831,config.util。ConfigProperty@22ceb311]“``如果没有其他定义,它将使用toString()
方法来显示数据。因此,它显示了Id和ConfigProperties列表。是否要在树ID中同时显示ConfigID和ConfigProperties?如果他们需要一个通用的超类,那么在同一个网格中不能有两个不同的类。非常感谢。它现在的工作方式好像您还没有向树网格中添加任何列:)您可以查看addColumn方法,或者使用新的TreeGrid(ConfigId.class)代码>自动生成。我更新了代码,现在我至少可以得到一些显示,即使结果不是预期的TreeGrid serviceGrid=新的TreeGrid(ConfigId.class);我得到的结果如下所示,ConfigProperty Id calibration.instance.storage[config.util。ConfigProperty@2b93bdff,config.util。ConfigProperty@3340c66d,config.util。ConfigProperty@67d10831,config.util。ConfigProperty@22ceb311]“``如果没有其他定义,它将使用toString()
方法来显示数据。因此,它显示了Id和ConfigProperties列表。是否要在树ID中同时显示ConfigID和ConfigProperties?如果他们需要一个通用的超类,那么在同一个网格中不能有两个不同的类。非常感谢。现在开始工作了
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);
Service Id, Name, Type, Value
service1
minutes, STRING, 120
seconds, STRING, 60
hours, STRING, 1
service2
host, STRING, localhost
port, STRING, 8080