3.5.3.4.1. Declarative Creation of Data Components

The simplest way to create data components for a screen is to define them in the screen XML descriptor in the <data> element.

Let’s consider the data model consisting of Customer, Order and OrderLine entities. The edit screen for the Order entity can have the following XML definition:

<data> (1)
    <instance id="orderDc" class="com.company.sales.entity.Order"> (2)
        <view extends="_local"> (3)
            <property name="lines" view="_minimal">
                <property name="product" view="_local"/>
                <property name="quantity"/>
            </property>
            <property name="customer" view="_minimal"/>
        </view>

        <loader/> (4)

        <collection id="linesDc" property="lines"/> (5)
    </instance>

    <collection id="customersDc" class="com.company.sales.entity.Customer" view="_minimal"> (6)
        <loader> (7)
            <query><![CDATA[select e from sales_Customer e]]></query>
        </loader>
    </collection>
</data>

In this case, the following data components are created:

1 - DataContext instance.
2 - InstanceContainer the Order entity.
3 - Inline view of the entity instance located in the container. Inline views can extend shared (defined in views.xml) ones.
4 - InstanceLoader which loads the Order instance.
5 - CollectionPropertyContainer for the nested OrderLines entity. It is bound to the Order.lines collection attribute.
6 - CollectionContainer for the Customer entity. The view attribute can point to a shared view.
7 - CollectionLoader which loads Customer entity instances using the specified query.

The data containers can be used in visual components as follows:

<layout>
    <dateField dataContainer="orderDc" property="date"/> (1)
    <form id="form" dataContainer="orderDc"> (2)
        <column>
            <textField property="amount"/>
            <lookupPickerField id="customerField" property="customer"
                               optionsContainer="customersDc"/> (3)
        </column>
    </form>
    <table dataContainer="linesDc"> (4)
        <columns>
            <column id="product"/>
            <column id="quantity"/>
        </columns>
    </table>
1 Standalone fields have dataContainer and property attributes.
2 form propagates dataContainer to its fields so they need only property attribute.
3 Lookup fields have optionsContainer attribute.
4 Tables have only dataContainer attribute.