Multiple embedded screen generation errors

Hi,

i have encountered the following situation in studio 2.2.2 and i think it is a bug if not multiple. Here’s the situation:

I created an Entity Customer with attributes “name: string”, “address: Address”, “deliveryAddress: Address”. The Address is an embedded entity with the attributes “street: string”, “city: string”.

I create a view for the customer containing both addresses and their attributes (“customer-view”). When i now generate screens for the customer with the “customer-view”, it creates the following “customer-edit.xml”:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://editCaption"
        class="com.company.exampleembedded.web.customer.CustomerEdit"
        datasource="customerDs"
        focusComponent="fieldGroup"
        messagesPack="com.company.exampleembedded.web.customer">
    <dsContext>
        <datasource id="customerDs"
                    class="com.company.exampleembedded.entity.Customer"
                    view="customer-view">
            <datasource id="addressDs"
                        property="address"/>
            <datasource id="deliveryAddressDs"
                        property="deliveryAddress"/>
        </datasource>
    </dsContext>
    <layout expand="windowActions"
            spacing="true">
        <fieldGroup id="fieldGroup"
                    datasource="customerDs">
            <column width="250px">
                <field id="name"/>
                <field id="street"
                       datasource="deliveryAddressDs"/>
                <field id="city"
                       datasource="deliveryAddressDs"/>
            </column>
        </fieldGroup>
        <frame id="windowActions"
               screen="editWindowActions"/>
    </layout>
</window>

Basically the attribute “address” is missing. Nevertheless, the “addressDs” gets created. When changing the implementation to also include the “address” attributes like this:


        <fieldGroup id="fieldGroup"
                    datasource="customerDs">
            <column width="250px">
                <field id="name"/>
                <field id="street"
                       datasource="deliveryAddressDs"/>
                <field id="city"
                       datasource="deliveryAddressDs"/>
                <field id="street"
                       datasource="addressDs"/>
                <field id="city"
                       datasource="addressDs"/>
            </column>
        </fieldGroup>

i get a runtime exception when open the customer editor:

GuiDevelopmentException: FieldGroup column contains duplicate fields 'street'.

Frame ID: exampleembedded$Customer.edit
XML descriptor: com/company/exampleembedded/web/customer/customer-edit.xml
FieldGroup ID: fieldGroup

Which is reasonable.

I ended up with the following implementation:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://editCaption"
        class="com.company.exampleembedded.web.customer.CustomerEdit"
        datasource="customerDs"
        focusComponent="fieldGroup"
        messagesPack="com.company.exampleembedded.web.customer">
    <dsContext>
        <datasource id="customerDs"
                    class="com.company.exampleembedded.entity.Customer"
                    view="customer-view" />
    </dsContext>
    <layout expand="windowActions"
            spacing="true">
        <fieldGroup id="fieldGroup"
                    datasource="customerDs">
            <column width="250px">
                <field id="name"/>
                <field id="deliveryAddress.street" caption="Delivery Address Street"/>
                <field id="deliveryAddress.city" caption="Delivery Address City"/>
                <field id="address.street" caption="Address Street"/>
                <field id="address.city" caption="Address Street"/>
            </column>
        </fieldGroup>
        <frame id="windowActions"
               screen="editWindowActions"/>
    </layout>
</window>

Initially i created only the address attribute on the customer and generated the screens - which worked fine. After i added the “deliveryAddress” attribute to the customer and studio wanted to adjust the existing editor screen - instead of adding the attribute it changed the super class of the editor to “AbstractWindow” which lead to the situation that after a click on edit i got an exception saying i count not cast CustomerEdit to AbstractEditor.

Attached you’ll find the example project at the state with the wrong generated edit screen.

Perhaps you might take a look. That would be great!

Bye,
Mario

example-embedded.zip (80.9K)

Hi,
Thank you for reporting the issue. It will be fixed in the Studio.

One more possible way to solve the problem with similar Id is to relocate address-fields to the separate fieldGroup (with the addressDs assigned to it).

Hi
The problem with screens generation is fixed in the Studio version 2.2.4.

Now the Studio automatically generates fields for one embedding (‘address’ in your sample). Fields for ‘delivery address’ should be added manually (in a separate FieldGroup f.e.).

In the Studio 2.2.4 the following behavior is implemented:

  1. If an entity has multiple embedded attributes with the same type and all of them are included to view.
    When you generate screens by the view:
  • Studio puts all the selected attributes on the 'browse' screen.
  • On the 'edit' screen only one embedded attribute is added to the FieldGroup automatically. Other embedded attributes should be located on the 'edit' screen manually.
2) If the screens for entity have been already generated. When you add a new embedded attribute and choose to append it to screens:
  • Studio just adds the attribute to screens. So the described ID conflict occurs. We are planning to fix it in future.

Regarding the unwanted transformation of ‘edit’ and ‘browse’ screens to the “AbstractWindow”:

  • The problem takes place only when the screen has not been modified (in Studio or IDE) after creation.
  • The issue is fixed in the Studio version 2.3. You can find the Studio 2.3.0RC1 here: [url=https://www.cuba-platform.com/blog/2016-09-05/587]https://www.cuba-platform.com/blog/2016-09-05/587[/url]

Hi

In the Studio 6.3.0 multiple embedded attributes are put to different fieldGroups.
The described problems should not occur.