Instance and Collection in the same screen

Hi guys,

In my domain: an animal Family (ie: Mammals) have several Species (ie: dogs, cats), I’m trying to program a screen where an instance of Family (MAM: Mammals) is shown with its collection of Species. When I try to create a new record for Species, the detail screen is asking for its corresponding Family.

family-species-1
family-species-2
family-species-3

Shouldn’t the framework already know about that foreign key and auto-fill it? (I know that I can hide the field, just showing it here on purpose).

This is my Family Detail View:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<view xmlns="http://jmix.io/schema/flowui/view"
      title="msg://familiaDetailView.title"
      focusComponent="form">
    <data>
        <instance id="familiaDc"
                  class="com.company.jmixprueba.entity.Familia">
            <loader/>
            <collection id="especiesDc" property="especies"/>
        </instance>
    </data>
    <facets>
        <dataLoadCoordinator auto="true"/>
    </facets>
    <actions>
        <action id="saveAction" type="detail_saveClose"/>
        <action id="closeAction" type="detail_close"/>
    </actions>
    <layout>
        <formLayout id="form" dataContainer="familiaDc">
            <textField id="codigoField" property="codigo"/>
            <textField id="descripcionField" property="descripcion"/>
        </formLayout>
        <nativeLabel text="Especies"/>
        <hbox id="buttonsPanel" classNames="buttons-panel">
            <button action="especiesDataGrid.create"/>
            <button action="especiesDataGrid.edit"/>
            <button action="especiesDataGrid.remove"/>
        </hbox>
        <dataGrid id="especiesDataGrid" dataContainer="especiesDc" width="100%" height="100%">
            <actions>
                <action id="create" type="list_create"/>
                <action id="edit" type="list_edit"/>
                <action id="remove" type="list_remove"/>
            </actions>
            <columns>
                <column property="version"/>
                <column property="tenantId"/>
                <column property="nombreComun"/>
                <column property="nombreCientifico"/>
                <column property="createdBy"/>
                <column property="createdDate"/>
                <column property="lastModifiedBy"/>
                <column property="lastModifiedDate"/>
            </columns>
        </dataGrid>
        <hbox id="detailActions">
            <button id="saveAndCloseBtn" action="saveAction"/>
            <button id="closeBtn" action="closeAction"/>
        </hbox>
    </layout>
</view>

And this is my Species Detail View:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<view xmlns="http://jmix.io/schema/flowui/view"
      title="msg://especieDetailView.title"
      focusComponent="form">
    <data>
        <instance id="especieDc"
                  class="com.company.jmixprueba.entity.Especie">
            <fetchPlan extends="_base">
                <property name="familia" fetchPlan="_base"/>
            </fetchPlan>
            <loader/>
        </instance>
    </data>
    <facets>
        <dataLoadCoordinator auto="true"/>
    </facets>
    <actions>
        <action id="saveAction" type="detail_saveClose"/>
        <action id="closeAction" type="detail_close"/>
    </actions>
    <layout>
        <formLayout id="form" dataContainer="especieDc">
            <textField id="nombreComunField" property="nombreComun"/>
            <textField id="nombreCientificoField" property="nombreCientifico"/>
            <entityPicker id="familiaField" property="familia">
                <actions>
                    <action id="entityLookup" type="entity_lookup"/>
                    <action id="entityClear" type="entity_clear"/>
                </actions>
            </entityPicker>
        </formLayout>
        <hbox id="detailActions">
            <button id="saveAndCloseBtn" action="saveAction"/>
            <button id="closeBtn" action="closeAction"/>
        </hbox>
    </layout>
</view>

I followed Mario David’s tutorial and, to my knowledge, I have followed the same steps he is explaining here:
Product-Prices

Thanks in advance.

Hi Eduardo.

In Jmix 2.x when you open editor this way it is opened as new web page. In this case you should set reference manually or provide parent object to the new page and handle it.

If you want to create\edit some nested object within parent object in the same web page you should open nested editor in dialog mode. In this case reference will be set automatically

Add the following property to target action:

<action id="create" type="list_create">
    <properties>
        <property name="openMode" value="DIALOG"/>
    </properties>
</action>

Regards,
Ivan

Perfect! Thank you!

Captura de pantalla 2024-04-05 a las 12.27.57