Setting field value based on result from valueCollectionDatasource


I create valueCollectionDatasource which return sum of amount. Query below

select COALESCE(sum(c.destinationDocument.brutto),0) as settled 
from demo$amountConnector c 

This datasource depend on other dataSource xxxCreatorParamsDs
Now I’d set result settled to field in editWindow. I try set datasource parameter for settled field.


I check datasource return correctly values. How can I set result from
sumDS datasource to column in xxxCreatorParamsDs datasource. Maybe there is other way for realize this case.

Hi Andrzej

The value datasources/data containers contain instances of KeyValueEntity which is an entity with attributes defined at runtime, in <properties> element of the datasource. So you can bind the visual components to these attributes as to regular entities/attributes.

Below is an example based on the GitHub - cuba-platform/sample-sales-cuba7: CUBA Platform Sample application project and new data containers API.

First, let’s define the value data container and the field bound to it in order-browse.xml:

<window xmlns="" ...>
    <data readOnly="true">
        <collection id="ordersDc" class="" view="order-with-customer">
            <loader id="ordersDl">
                    <![CDATA[select e from sales_Order e]]>
        <keyValueInstance id="orderAmountDc">
            <loader id="orderAmountDl">
                <query>select sum(e.quantity * e.product.price) from sales_OrderLine e where e.order = :order</query>
                <property name="amount" datatype="decimal"/>
    <layout expand="ordersTable"
        <groupTable ...>
            <buttonsPanel ...>
                <textField id="amountField" inputPrompt="Amount of the selected order"
                           dataContainer="orderAmountDc" property="amount"/>

After that, change OrderBrowse controller as follows:

// notice there is no @LoadDataBeforeShow annotation
public class OrderBrowse extends StandardLookup<Order> {

    private CollectionLoader<Order> ordersDl;
    private KeyValueInstanceLoader orderAmountDl;

    private void onBeforeShow(BeforeShowEvent event) {
        // load orders list right before screen opening

    @Subscribe(id = "ordersDc", target = Target.DATA_CONTAINER)
    private void onOrdersDcItemChange(InstanceContainer.ItemChangeEvent<Order> event) {
        // load order amount each time an order is selected 
        orderAmountDl.setParameter("order", event.getItem());


As for datasources, there is no direct counterpart to keyValueInstance container, so you should use ValueCollectionDatasource and set the first loaded item in it after refreshing.