Help with v7 lookupFIeld

Hi:

I have a very basic lookupField with an optionsContainer, but for some reason I can’t get it to show the instance name in the dropdown when it is loaded. Here’s the Entity Inspector. The indicated field has the data I want to show:

image

Here’s my Editor screen (v7) for the same Entity:

image

Here’s how the field is defined in my Customer entity:

image

Controller is the default generated code:

package com.paslists.custfm.web.customers;

import com.haulmont.cuba.gui.screen.*;
import com.paslists.custfm.entity.Customers;

@UiController("custfm_Customers.edit")
@UiDescriptor("customers-edit.xml")
@EditedEntityContainer("customersDc")
@LoadDataBeforeShow
public class CustomersEdit extends StandardEditor<Customers> {
}

XML is:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
        caption="msg://editorCaption"
        focusComponent="grpBoxCustomer"
        messagesPack="com.paslists.custfm.web.customers">
    <data>
        <instance id="customersDc" class="com.paslists.custfm.entity.Customers" view="customers-view">
            <loader/>
        </instance>
        <collection id="radeMasterDc" class="com.paslists.custfm.entity.Customers" view="rademasters_view">
            <loader id="radeMasterDl">
                <query><![CDATA[select e from custfm_Customers e
where e.respschema is not null
order by e.company]]></query>
            </loader>
        </collection>
    </data>
    <dialogMode height="600"
                width="800"/>
    <layout expand="editActions" spacing="true">
        <tabSheet id="tabsMain" stylename="framed">
            <tab id="tabGeneral" caption="General">
                <hbox spacing="true">
                    <groupBox id="grpBoxCredit" caption="Credit Status">
                        <textField id="creditstatusField" dataContainer="customersDc" property="creditstatus"/>
                    </groupBox>
                    <groupBox id="grpBoxGeneral" caption="General">
                        <flowBox spacing="true">
                            <label value="Acct Rep"/>
                            <textField id="acctrepField" dataContainer="customersDc" property="acctrep" width="150px"/>
                            <label value="Custom Tag"/>
                            <textField id="customtagField" dataContainer="customersDc" property="customtag" width="100px"/>
                        </flowBox>
                    </groupBox>
                </hbox>
                <hbox id="hboxMain" spacing="true">
                    <groupBox id="grpBoxCustomer" caption="Address" spacing="true" width="AUTO">
                        <grid spacing="true">
                            <columns count="2"/>
                            <rows>
                                <row>
                                    <label value="Company"/>
                                    <textField id="companyField" dataContainer="customersDc" property="company" />
                                </row>
                                <row>
                                    <label value="Division"/>
                                    <textField id="divisionField" property="division"/>
                                </row>
                                <row>
                                    <label value="Sec Addr"/>
                                    <textField id="address2Field" dataContainer="customersDc" property="address2"/>
                                </row>
                                <row>
                                    <label value="Prim Addr"/>
                                    <textField id="address1Field" dataContainer="customersDc" property="address1"/>
                                </row>
                                <row>
                                    <label value="City"/>
                                    <hbox spacing="true">
                                        <textField id="cityField" dataContainer="customersDc" property="city"/>
                                        <textField id="stateField" dataContainer="customersDc" property="state" width="40px" maxLength="2"/>
                                        <textField id="zipField" dataContainer="customersDc" property="zip" width="70px" maxLength="5"/>
                                        <textField id="zip4Field" dataContainer="customersDc" property="zip4" width="50px" maxLength="4"/>
                                    </hbox>
                                </row>
                                <row>
                                    <label value="Country"/>
                                    <textField id="countryField" property="country"/>
                                </row>
                                <row>
                                    <label value="Contact"/>
                                    <textField id="contactField" property="contact"/>
                                </row>
                            </rows>
                        </grid>
                    </groupBox>
                    <groupBox id="grpBoxContact" spacing="true" caption="Contacts">
                        <grid spacing="true">
                            <columns count="2"/>
                            <rows>
                                <row>
                                    <label value="Phone"/>
                                    <textField id="phoneField" property="phone"/>
                                </row>
                                <row>
                                    <label value="Fax"/>
                                    <textField id="faxField" property="fax"/>
                                </row>
                                <row>
                                    <label value="EMail"/>
                                    <textField id="emailField" property="email"/>
                                </row>
                                <row>
                                    <label value="M/P Status E-Mail"/>
                                    <textField id="mpemailField" property="mpemail"/>
                                </row>
                                <row>
                                    <label value="Reports E-Mail"/>
                                    <textField id="rptemailField" property="rptemail"/>
                                </row>
                                <row>
                                    <label value="Upd Req E-Mail"/>
                                    <textField id="updreqemailField" property="updreqemail"/>
                                </row>
                                <row>
                                    <label value="ePAF E-Mail"/>
                                    <textField id="pafemailField" property="pafemail"/>
                                </row>
                            </rows>
                        </grid>
                    </groupBox>
                    <groupBox id="grpBoxRADE" caption="RADE" spacing="true">
                        <grid spacing="true">
                            <columns count="2"/>
                            <rows>
                                <row>
                                    <label value="Response Schema"/>
                                    <textField id="respschemaField" dataContainer="customersDc" property="respschema"/>
                                </row>
                                <row>
                                    <label value="Response Password"/>
                                    <textField id="resppwdField" dataContainer="customersDc" property="resppwd"/>
                                </row>
                                <row>
                                    <label value="RADE Master"/>
                                    <lookupField dataContainer="customersDc" property="rademaster" optionsContainer="radeMasterDc" />
                                </row>
                                <row>
                                    <label value="RADE Suppress"/>
                                </row>
                            </rows>
                        </grid>
                    </groupBox>
                </hbox>
            </tab>
        </tabSheet>
        <hbox id="editActions" spacing="true">
            <button action="windowCommitAndClose"/>
            <button action="windowClose"/>
        </hbox>
    </layout>
</window>

The lookupField only displays customers where the respschema field is not null (radeMasterDc/radeMasterDl). The record in question (Trimark) fits the criteria (it contains “TMK”).

Here are the views:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<views xmlns="http://schemas.haulmont.com/cuba/view.xsd">

    <view entity="custfm_Customers" name="customers-view" extends="_local">
        <property name="rademaster" view="rademasters_view"/>
        <property name="salesrepFk" view="_minimal"/>
        <property name="mergedeliv" view="_minimal">
            <property name="countflag"/>
            <property name="delivcc"/>
            <property name="delivemail"/>
            <property name="delivervia"/>
            <property name="delivpwd"/>
            <property name="delivuser"/>
            <property name="directory"/>
            <property name="filepatterns"/>
            <property name="finderlen"/>
            <property name="finderpos"/>
            <property name="keylen"/>
            <property name="keypos"/>
            <property name="layout"/>
            <property name="port"/>
            <property name="reclen"/>
            <property name="sshkeyfile"/>
            <property name="template"/>
            <property name="typeflag"/>
            <property name="unzipped"/>
            <property name="weburl"/>
        </property>
        <property name="repdefs" view="_minimal">
            <property name="printer"/>
            <property name="repnum"/>
            <property name="reporder"/>
            <property name="report"/>
        </property>
        <property name="custreps" view="_minimal">
            <property name="rep" view="_minimal">
                <property name="address1"/>
                <property name="address2"/>
                <property name="city"/>
                <property name="commpcnt"/>
                <property name="country"/>
                <property name="division"/>
                <property name="email"/>
                <property name="fax"/>
                <property name="phone"/>
                <property name="ptid"/>
                <property name="state"/>
                <property name="zip"/>
                <property name="zip4"/>
            </property>
            <property name="commpcnt"/>
        </property>
        <property name="custrels" view="_minimal">
            <property name="bc" view="_minimal">
                <property name="activeflag"/>
                <property name="delivcv"/>
                <property name="mpemail"/>
                <property name="tapestatbkr"/>
            </property>
            <property name="acctexecflag"/>
            <property name="delivcv"/>
            <property name="tapestatus"/>
        </property>
    </view>
    <view entity="custfm_Customers" name="rademasters_view" extends="_minimal">
        <property name="respschema"/>
    </view>
</views>

Please help me make this work. I am missing something simple, I’m sure.

Hi,
First thing - it is not clear from the content you posted what type of field is “company”.

Instance name is based on “company” field, so you may try to add it manually to related entity views.

The case you posted looks like a bug. If you will be able to reproduce this situation on a small demo project, CUBA team will have more chances to identify source of the problem and fix it.

Thank you. Company is a java.lang.String.

In any event, I found myriad issues in my associations that must have caused the problem. Biggest one is I have an embedded composite key where one part is a constant for this application. Really poor design, but I was young and stupid… ;-). As soon as I fixed this issue, all of my related entities started loading properly. My guess is that Eclipselink was failing but I just did not see the error.

Worse yet, the key is for a different association entirely, so I was trying to debug the wrong problem. For those who follow, maybe this will be useful:

The Jobdefs table holds job defaults, with an embedded key consisting of Customer ID and Job ID. The defaults for a customer were originally stored with a null for Job ID and the appropriate Customer ID. Since null is not a valid value for an Eclipselink primary key field, I changed my legacy system to use -1 instead (an invalid Job ID). Then I had to tell the system that I only wanted the records where Job ID is -1 for this application. My solution, which may or may not be the best one, was to add this to my Jobdefs entity:

@MetaClass(name = "custfm_JobdefsCompKey")
@Embeddable
public class JobdefsCompKey extends EmbeddableEntity {
    private static final long serialVersionUID = -8702137759981849222L;

    @Column(name = "CUS_ID")
    protected Long cus;
    @Column(name = "JOB_ID")
    protected Long job;

   <standard hashCode, equals, getters, setters >
}
@Table(name = "JOBDEFS")
@Entity(name = "custfm_Jobdefs")
public class Jobdefs extends BaseGenericIdEntity<JobdefsCompKey> {
    private static final long serialVersionUID = 2913012589319426949L;

    @EmbeddedId
    protected JobdefsCompKey id;

    @MapsId("cus")
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CUS_ID")
    protected Customers customer;

    public Long getJobId() {
        return id.getJob();
    }

    public void setJobId() { 
        id.setJob(-1L);   // FORCE JOB_ID = -1
    }

    <lots of fields>

    @PrePersist
    public void prePersist() {
        if (getId().getJob() == null) {
            getId().setJob(-1L);  // FORCE JOB_ID = 1
        }
    }
}

I need to do a lot more testing, but this seems to work. And, once I got this working, my rademaster field magically populated again.

Thanks for your attention on this.