Display read-only attributes from related entity

Greetings everyone.

I am looking for some help with regards to displaying related entity attributes on Edit screen. It is working fine if i select the related entity via the lookup action. However, if i select the related entity with the drop-down list, the related entity attribute is not refreshed.

For example, in the Sales application’s Order edit screen, i added the email attribute of the Customer entity as a display-only field. When i select a different customer in the Order edit screen using the drop-drown list, the customer’s email does not changed. Is there a way to refresh the email attribute when the customer is selected from the drop-down list? Selecting the customer via the lookup action is fine as the whole Order edit screen is refreshed after returning from the customer lookup screen.

Below is the screen XML of the Order edit screen. Much appreciate for your help or suggestion.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://editCaption"
        class="com.company.sales.gui.order.OrderEdit"
        datasource="orderDs"
        focusComponent="fieldGroup"
        messagesPack="com.company.sales.gui.order">
    <dsContext>
        <datasource id="orderDs"
                    class="com.company.sales.entity.Order"
                    view="order-edit">
            <collectionDatasource id="linesDs"
                                  property="lines"/>
        </datasource>
        <collectionDatasource id="customersDs"
                              class="com.company.sales.entity.Customer">
            <query>
                <![CDATA[select e from sales$Customer e]]>
            </query>
        </collectionDatasource>
    </dsContext>
    <layout expand="linesTable"
            spacing="true">
        <fieldGroup id="fieldGroup"
                    datasource="orderDs">
            <column>
                <field id="date"
                       width="200px"/>
                <field id="amount"
                       width="200px"/>
                <field id="customer"
                       optionsDatasource="customersDs"
                       width="200px"/>
                <field id="customer.email"
                       editable="false"/>
            </column>
        </fieldGroup>
        <buttonsPanel>
            <button action="linesTable.create"/>
            <button action="linesTable.edit"/>
            <button action="linesTable.remove"/>
        </buttonsPanel>
        <table id="linesTable"
               width="350px">
            <actions>
                <action id="create"/>
                <action id="edit"/>
                <action id="remove"/>
            </actions>
            <columns>
                <column id="product.name"/>
                <column id="product.price"/>
                <column id="quantity"/>
            </columns>
            <rows datasource="linesDs"/>
        </table>
        <frame id="windowActions"
               screen="editWindowActions"/>
    </layout>
</window>

Hi David,
Create a nested datasource for the customer object and use it for the “email” field:


<dsContext>
    <datasource id="orderDs" class="com.company.sales.entity.Order" view="order-edit">
        <datasource id="customerDs" property="customer"/>
    </datasource>
    <collectionDatasource id="customersDs" class="com.company.sales.entity.Customer" view="_local">
        <query>
            <![CDATA[select e from sales$Customer e]]>
        </query>
    </collectionDatasource>
</dsContext>
<layout expand="windowActions" spacing="true">
    <fieldGroup id="fieldGroup" datasource="orderDs">
        <column>
            <field id="date" width="250px"/>
            <field id="amount" editable="false" width="250px"/>
            <field id="customer" datasource="orderDs" optionsDatasource="customersDs" width="250px"/>
            <field id="email" datasource="customerDs"/>
        </column>
    </fieldGroup>
...

And don’t forget to include customer.email attribute to the “order-edit” view.

Hi Konstantin,

Thank you very much for your answer. It’s working wonderfully :slight_smile:

This also help me understand View and Datasource relationship much better. Thanks!

Best regards,
David See