Hi,
I want to use a JsonDataSource to bind Data to the Form[1] and to a Grid[2] at the same time.
The json-string:
{"command":{
"firstname":"Steve",
"lastname":"Miller",
"table":[
{"id":"1","data":"15-01-2009","sport":"Soccer","color":"ff0000"},
{"id":"2","data":"15-01-2009","sport":"Cricket","color":"00ff00"},
{"id":"3","data":"15-01-2009","sport":"Rugby","color":"0000ff"}
]
}
Now I want to bind the firstname and the lastname property to a form
and the table property to a grid.
The database is defined like following Code Block.
And here the Problem:
if “dataSource.setRecordXPath(”/command/table");" exists the table values are displayed and the form values are not displayed. If not the form-values are displayed and the table values are not displayed.
Is there a way to use the DataSource for the Form and the Grid at the same time?
Regards
Kai
The DataSource:
DataSource dataSource = new DataSource();
dataSource.setDataFormat(DSDataFormat.JSON);
dataSource.setDataURL("/test/hello.json");
/*
* If next line exists the table values are displayed and the formvalues not
* If next line is removed the form-values are displayed and the table values not.
*/
dataSource.setRecordXPath("/command/table");
/*
* FormFelds
*/
DataSourceTextField firstnameField = new DataSourceTextField( "firstname", "Firstname");
firstnameField.setValueXPath("/command/firstname");
DataSourceTextField lastnameField = new DataSourceTextField( "lastname", "Lastname");
lastnameField.setValueXPath("/command/lastname");
/*
* GridFelds
*/
DataSourceTextField sportField = new DataSourceTextField( "sport", "Sport");
DataSourceTextField dataField = new DataSourceTextField( "data", "Data");
DataSourceTextField colorField = new DataSourceTextField( "color", "Color");
dataSource.setFields(new DataSourceField[] { firstnameField, lastnameField, sportField, dataField, colorField });
The form is defined like
final DynamicForm preferencesForm = new DynamicForm();
preferencesForm.setDataSource(dataSource);
TextItem lastname = new TextItem();
lastname.setTitle("Lastname");
lastname.setName("lastname");
TextItem firstname = new TextItem();
firstname.setTitle("Firstname");
firstname.setName("firstname");
preferencesForm.setFields(firstname, lastname);
preferencesForm.setAutoFetchData(true);
The grid is defined like
final ListGrid countryGrid = new ListGrid();
countryGrid.setShowAllRecords(true);
countryGrid.setDataSource(dataSource);
countryGrid.setAutoFetchData(true);
ListGridField sportField = new ListGridField("sport", "Sport");
ListGridField dataField = new ListGridField("data", "Data");
ListGridField colorField = new ListGridField("color", "Color");
countryGrid.setFields(new ListGridField[] {sportField, dataField, colorField});