one-to-one edit in same screen

I’m just getting started with Cuba Platform and Studio, so this may be a pretty basic question. I have two entities (Visit and Mse) in a one-to-one relationship (with Visit owning). When I open a screen to create a new Visit, I would like to be able to edit its attributes (right now, just “date”) and also those of Mse (right now, just “appearance”) from the same editor screen. Both entities should be created, edited, and saved together. I’ve tried doing this in the attached example. In the Visit editor, there is a date picker (which works fine) and a text box for appearance (which refuses to save its data). Where am I going wrong?
Thanks
Eric

the file…

Hi Eric,

can you share the screen xml of the editor? It seems you did not attached the example.

General you can find a working solution of a one-to-one association here: https://www.cuba-platform.com/discuss/t/issue-dealing-with-one-to-one-entity-relationship

Bye
Mario

Not sure what happened to the file… I’m trying the upload again. Thanks for the link

For whatever reason, it’s not letting me upload a zip of the cuba studio project. So, here’s just the XML of the screen



<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://editorCaption"
        class="com.company.clinicb.web.visit.VisitEdit"
        datasource="visitDs"
        focusComponent="fieldGroup"
        messagesPack="com.company.clinicb.web.visit">
    <dsContext>
        <datasource id="visitDs"
                    class="com.company.clinicb.entity.Visit"
                    view="visit-with-mse">
            <datasource id="visitMseDs"
                        property="mse"></datasource>
        </datasource>
    </dsContext>
    <dialogMode height="600"
                width="800"></dialogMode>
    <layout expand="windowActions"
            spacing="true">
        <fieldGroup id="fieldGroup"
                    datasource="visitDs">
            <column width="250px">
                <field id="date"></field>
            </column>
        </fieldGroup>
        <textField datasource="visitMseDs"
                   property="appearance"></textField>
        <frame id="windowActions"
               screen="editWindowActions"></frame>
    </layout>
</window>

Hi Eric,

Your screen descriptor looks completely correct. I think you have missed one thing - to instantiate the related Mse object when you are creating Visit. It should be done in the initNewItem() method of the screen controller:

@Inject
private Metadata metadata;

@Override
protected void initNewItem(Visit item) {
    item.setMse(metadata.create(Mse.class));
}

The platform (CreateAction in fact) instantiates nested objects automatically only if they are Embeddable.

1 Like

Thank you!!!