get all fields from DynamicForm
Asked Answered
T

2

6

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?

Trouper answered 18/10, 2012 at 10:11 Comment(0)
T
0

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

Trouper answered 22/10, 2012 at 18:2 Comment(0)
C
1

I m not exactly sure if this will solve your issue. CompanySlaves is not references in any where in xsd. Type is defined but not used.

I think you need to have <xsd:element name="SomeElementName" type="tns:CompanySlaves"></xsd:element> in your xsd definition

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://xml.netbeans.org/schema/newXmlSchema"
    xmlns:tns="http://xml.netbeans.org/schema/newXmlSchema"
    elementFormDefault="qualified">
    <xsd:element name="SubrogationClaim" type="tns:SubrogationClame"></xsd:element>
    <xsd:complexType name="SubrogationClame">
        <xsd:sequence>
            <xsd:element name="CompanyName" type="xsd:string"></xsd:element>
            <xsd:element name="CompanyPlace" type="xsd:string"></xsd:element>
            <xsd:element name="CompanyEmploee" type="tns:SubrogationClame"></xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="CompanySlaves">
        <xsd:sequence>
            <xsd:element name="EmploeeName" type="xsd:string"></xsd:element>
            <xsd:element name="EmploeeSalary" type="xsd:string"></xsd:element>
        </xsd:sequence>
    </xsd:ComplexType>
</xsd:schema>
Chiasma answered 21/10, 2012 at 5:35 Comment(0)
T
0

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

Trouper answered 22/10, 2012 at 18:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.