Java SmartGWT数据源字符串XML
我目前正在使用SmartGWT网格,它使用一个数据源对象,该对象接收一个xml文件。这种方法很好,但我想知道是否可以发送一个xml结构的字符串。如下所示:Java SmartGWT数据源字符串XML,java,xml,datasource,smartgwt,Java,Xml,Datasource,Smartgwt,我目前正在使用SmartGWT网格,它使用一个数据源对象,该对象接收一个xml文件。这种方法很好,但我想知道是否可以发送一个xml结构的字符串。如下所示: String xml = "<listgrid><data><campo1></campo1>hola<campo2>mundo</campo2></data></listgrid>"; setData(xml); String xml=“hol
String xml = "<listgrid><data><campo1></campo1>hola<campo2>mundo</campo2></data></listgrid>";
setData(xml);
String xml=“holamundo”;
setData(xml);
这是一段伪代码,但应该能让读者有所了解
我搜索过,没有找到符合我要求的示例。有更好的方法。您要做的是动态填充数据源 下面是一个例子:
public void onModuleLoad() {
DataSourceTextField continentField = new DataSourceTextField("continent");
continentField.setPrimaryKey(true);
DataSource dataSource = new DataSource();
dataSource.setClientOnly(true);
dataSource.setFields(continentField);
for (CountryRecord record : new CountryData().getNewRecords()) {
dataSource.addData(record);
}
ListGrid myGrid = new ListGrid();
myGrid.setWidth(200);
myGrid.setHeight(100);
myGrid.setDataSource(dataSource);
myGrid.fetchData();
myGrid.draw();
}
class CountryData {
public CountryRecord[] getNewRecords() {
return new CountryRecord[] {
new CountryRecord("North America"),
new CountryRecord("Asia") };
}
}
class CountryRecord extends ListGridRecord {
public CountryRecord(String continent) {
setContinent(continent);
}
public void setContinent(String continent) {
setAttribute("continent", continent);
}
public String getContinent() {
return getAttributeAsString("continent");
}
}