0

I am currently using a SmartGWT grid, that uses a DataSource object, which receives an xml file. All is well with this approach, but I want to know if I can just send a string with an xml structure. Something like the below:

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

This is pseudo-code, but it should give an idea to the reader.

I've searched and found no example that fulfills my requirements.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Mariah
  • 1,073
  • 1
  • 14
  • 33

1 Answers1

2

There is a better way. What you want to do is populate the dataSource dynamically.

Here's an example:

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");
    }
}
Adel Boutros
  • 10,205
  • 7
  • 55
  • 89