I use DataSource generated from xsd schema. I need to get all fields from DataSource, also nested ones. My problem is the same like in this topic from Smartclient forum forum, when I use DataSource.getFields()
its return only first level fields.
Does anyone know how can I get also nested fields?
I found solution. To get nested fields it’s possible to use DataSource.getDataSource(ID). For example, if dataSource is main DataSource, it can be done like that:
private List<DataSourceField> getAllFields(DataSource dataSource)
{
List <DataSourceField> fieldList = new ArrayList<DataSourceField>();
DataSourceField [] fields = dataSource.getFields();
fieldList.addAll(Arrays.asList(fields));
for (DataSourceField field : fields);
{
String fieldName = field.getName();
DataSource ds = DataSource.getDataSource(fieldName);
if (ds != null)
{
fieldList.remove(field);
DataSourceField[] nFields = ds.getFields();
fieldList.addAll(Arrays.asList(nFields));
getAllFields(ds);
}
}
return fieldList;
}