【问题标题】:SmartGWT DataSource string XMLSmartGWT 数据源字符串 XML
【发布时间】:2012-05-02 17:37:15
【问题描述】:

我目前正在使用一个 SmartGWT 网格,它使用一个接收 xml 文件的 DataSource 对象。这种方法一切都很好,但我想知道我是否可以只发送一个带有 xml 结构的字符串。类似于以下内容:

String xml = "<listgrid><data><campo1></campo1>hola<campo2>mundo</campo2></data></listgrid>";
setData(xml);

这是伪代码,但它应该给读者一个想法。

我搜索并没有找到满足我要求的示例。

【问题讨论】:

    标签: java xml datasource smartgwt


    【解决方案1】:

    有更好的方法。您要做的是动态填充数据源。

    这是一个例子:

    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");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-06-12
      • 2011-02-18
      • 2012-08-28
      • 2011-03-12
      • 1970-01-01
      • 1970-01-01
      • 2014-02-14
      • 2011-05-08
      • 1970-01-01
      相关资源
      最近更新 更多