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>
    <instance id="orderDc" class="com.company.sales.entity.Order" view="order-edit">
        <loader/>

        <collection id="linesDc" property="lines"/>
    </instance>

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

In this case, the following data components are created:

  • DataContext instance.

  • InstanceContainer with orderDc id and InstanceLoader for the Order entity.

  • CollectionPropertyContainer with linesDc id for the OrderLines entity. It is bound to the Order.lines collection attribute.

  • CollectionContainer with customersDc id for the Customer entity. It is loaded by CollectionLoader 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.