KeyValueContainer and TextField don't work together

Hi, i’m trying to connect a “KeyValueEntity” dataset to a TextField but in designtime i can’t set the property field. Anyway when i tryed from runtime using “setValueSource” method i can see the value assigned to the dataset but it is read only. others properties from the dataset that are not datatype worked well. Take a look to these lines:

Note: The dataset name is “lugarEntregaDc”

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
        caption="msg://editorCaption"
        focusComponent="form"
        messagesPack="com.company.caerp.web.comprobante">
    <data>
        <keyValueInstance id="lugarEntregaDc">
            <properties idProperty="id">
                <property name="id" datatype="uuid"/>
                <property name="vendedor" class="com.company.caerp.entity.Persona"/>
                <property name="vehiculo1" class="com.company.caerp.entity.Bien"/>
                <property name="vehiculo2" class="com.company.caerp.entity.Bien"/>
                <property name="cot" datatype="string"/>
                <property name="cliente" class="com.company.caerp.entity.Cliente"/>
                <property name="provincia" class="com.company.caerp.entity.Provincia"/>
            </properties>
            <loader id="lugarEntregaLc">
                <query>
                    <![CDATA[select e]]>
                </query>
            </loader>
        </keyValueInstance>
        <collection id="personaeDc" class="com.company.caerp.entity.Persona" view="_local">
            <loader id="personaeDl">
                <query>
                    <![CDATA[select e from caerp$Persona e ]]>
                </query>
            </loader>
        </collection>
        <collection id="clientesDc" class="com.company.caerp.entity.Cliente" view="_local">
            <loader id="clientesDl">
                <query>
                    <![CDATA[select e from caerp$Cliente e ]]>
                </query>
            </loader>
        </collection>
        <collection id="provinciasDc" class="com.company.caerp.entity.Provincia" view="_local">
            <loader id="provinciasDl">
                <query>
                    <![CDATA[select e from caerp$Provincia e ]]>
                </query>
            </loader>
        </collection>
        <instance id="comprobanteTransporteDc" class="com.company.caerp.entity.ComprobanteTransporte">
            <loader id="comprobanteTransporteDl"/>
        </instance>
    </data>
    <actions>
        <action id="ok"
                invoke="onOk"/>
        <action id="cancel"
                invoke="onCancel"/>
    </actions>
    <dialogMode height="400"
                width="700" forceDialog="true"/>
    <layout expand="scrollBox" spacing="true">
        <scrollBox id="scrollBox" spacing="true">
            <form id="form" dataContainer="lugarEntregaDc">
                <column width="250px">
                    <label icon="LIST" stylename="h2 bold" value="Informacion General:"/>
                    <lookupPickerField id="vendedorLEField" caption="msg://Vendedor LE"
                                       optionsContainer="personaeDc" property="vendedor">
                        <actions>
                            <action id="lookup" type="picker_lookup"/>
                            <action id="open" type="picker_open"/>
                        </actions>
                    </lookupPickerField>
                    <lookupPickerField id="clienteLEField" caption="msg://Cliente LE"
                                       optionsContainer="clientesDc" property="cliente"/>
                    <lookupPickerField id="provinciaLEField" caption="msg://Provincia LE"
                                       optionsContainer="provinciasDc" captionProperty="nombre"
                                       dataContainer="lugarEntregaDc" property="provincia"/>
                    <textField id="cotLEField" maxLength="0" dataContainer="lugarEntregaDc"/>
                    <textField id="observacionLEField" width="342px" height="73px"
                               caption="msg://Observacion LE" />
                </column>
            </form>
        </scrollBox>
        <hbox id="editActions" spacing="true">
            <button id="okBtn"
                    action="ok"
                    caption="mainMsg://actions.Ok"/>
            <button id="cancelBtn"
                    action="cancel"
                    caption="mainMsg://actions.Cancel"/>
        </hbox>
    </layout>
</window>

Here load values:

    @Install(to = "lugarEntregaLc", target = Target.DATA_LOADER)
    private KeyValueEntity lugarEntregaLcLoadDelegate(ValueLoadContext valueLoadContext) {

        KeyValueEntity keyValueEntity = new KeyValueEntity();

        keyValueEntity.setValue("id", UUID.randomUUID());
        keyValueEntity.setValue("vendedor", null);
        keyValueEntity.setValue("cliente", getCliente());
        keyValueEntity.setValue("provincia", getProvincia());
        keyValueEntity.setValue("vehiculo1", null);
        keyValueEntity.setValue("vehiculo2", null);
        keyValueEntity.setValue("cot", "00000000");

        return keyValueEntity;
    }

In design time i can’t view the properties options list.

image

In runtime i tryed this one (it worked for me in collections values datasets but here gave me some bugs):

image

let me clarify this point, the others fields works properly!.

Best regards

Hi,

Thanks for reporting the problem. I’ve checked your case.
Support from the Studio for keyValueInstance is not ideal, to say the least… Created ticket https://youtrack.cuba-platform.com/issue/STUDIO-8404

But this does not prevent you to specify “property” attribute value manually, in the XML code or in the corresponding Component Inspector “property” value cell.
This code snippet works fine for me. When the screen is opened, both fields are filled with values:

    <data>
        <keyValueInstance id="cardsDc">
            <properties>
                <property name="name" datatype="string"/>
                <property name="count" datatype="int"/>
            </properties>
            <loader id="cardsDl">
                <query>

                </query>
            </loader>
        </keyValueInstance>
    </data>
    <facets>
        <dataLoadCoordinator auto="true"/>
    </facets>
    <layout>
        <form dataContainer="cardsDc">
            <column>
                <textField id="name" property="name" caption="Name"/>
                <textField id="count" caption="Count" property="count"/>
            </column>
        </form>
    </layout>

Controller:

    @Install(to = "cardsDl", target = Target.DATA_LOADER)
    private KeyValueEntity cardsDlLoadDelegate(ValueLoadContext valueLoadContext) {
        KeyValueEntity kve = new KeyValueEntity();
        kve.setValue("name", "Foo");
        kve.setValue("count", 15);
        return kve;
    }

Hi Alex i tried your method as you described but functionally doesn’t works, if you try to modified the value on the textfield it has a strange behavior. i’m on plataform 7.1.5 version. and i get the same behavior using “setValueSource” from code.

Hi,
I’ve tried it on CUBA 7.1.5, and my sample works.
I’m sorry but I don’t understand what do you mean by “strange behavior”.

If you have problems, can you please explain in detail how it should work and what does not work? And ideally provide a small demo project with one screen where the problem is reproduced.

My demo project attached:
kvtext.zip (75.8 KB)

Your code works correctly. I searched the XML code of my screen and found that the component “textField” had the value “maxLength” assigned to zero … but I didn’t put that property there … Anyway I was able to solve the problem !.

thanks!.