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 name="customer" view="_minimal"/>

        <loader/> (4)

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

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

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:

    <dateField dataContainer="orderDc" property="date"/> (1)
    <form id="form" dataContainer="orderDc"> (2)
            <textField property="amount"/>
            <lookupPickerField id="customerField" property="customer"
                               optionsContainer="customersDc"/> (3)
    <table dataContainer="linesDc"> (4)
            <column id="product"/>
            <column id="quantity"/>
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.