Populate a Lookupfield - empty

I am trying to declaratively load a Lookupfield but the example code in documentation displays an empty Lookupfield. The entity table has data and then entity browser also shows data.

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

    <data>
        <instance id="tableGroupDc"
                  class="com.jsonedi.jediadmin.entity.TableGroup"
                  view="_local">
            <loader/>
        </instance>
    </data>
    <layout spacing="true">

        <lookupField  property="tGName" dataContainer="tableGroupDc">
        </lookupField>
    </layout>
</window>
package com.jsonedi.jediadmin.web.screens.tablegroup;

import com.haulmont.cuba.gui.screen.Screen;
import com.haulmont.cuba.gui.screen.UiController;
import com.haulmont.cuba.gui.screen.UiDescriptor;

@UiController("jediadmin_TableGroupFragment")
@UiDescriptor("table-group-fragment.xml")
public class TableGroupFragment extends Screen {
}

Try to add the @LoadDataBeforeShow annotation over your screen controller - it should help.

I did add @LoadDataBeforeShow after I submitted this post but still no help.

Is the fact my controller is a screen vs StandardLookup<> make a difference? The Cuba generated “browse” works fine. My goal is a screen with several dropdown controls populated from separate entities.

Got you finally. @LoadDataBeforeShow works fine. But you have installed wrong attributes for the lookup component. You should have set optionsContainer. See the example below:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
        caption="msg://caption"
        messagesPack="com.company.untitled3.web.screens">
    <data>
        <collection id="testDc"
                    class="com.company.untitled3.entity.TestEntity"
                    view="_local">
            <loader id="testDl">
                <query>
                    <![CDATA[select e from untitled3_TestEntity e]]>
                </query>
            </loader>
        </collection>
    </data>
    <layout>
        <lookupField caption="Custom lookup" optionsContainer="testDc"/>
    </layout>
</window>
@UiController("untitled3_CustomScreen")
@UiDescriptor("custom-screen.xml")
@LoadDataBeforeShow
public class CustomScreen extends Screen {

}

I would suggest paying more attention to the sampler application. It shows how to use UI components. See this example for using the lookup field: https://demo10.cuba-platform.com/sampler/open?screen=custom-options-lookupfield.

1 Like

I tried your code and the sample link. I tried this at least 20 different ways. I tried through the screen designers using the intelligent pickers and I get NO design time or compiling errors. I either get no data or runtime errors. I know I’m a newbie but . . . .

This is really odd. Thousands of people got trough this elementary stage with NO issues.

One additional note, I created my datamodel from the “generate model” in datastore (SQL Server). So my my entity class looks a little different then examples. But i even set it to a StandardEntity from the BaseIntegerIdEntity the generator chose. So I can’t see an issue there.

Can I have a webex meeting with someone to review our code and/or environment. I’ll pay if I have too.

Final resolution to populate the dropdown values in a LookupField was I was binding to dataContainer=“xxx” and property=“xxx”
but what I needed to do is bind to is optionContainer and captionProperty. These are what the populate the dropdown.
I also bound dataContainer/property to instance of my class
Then on some screen event I got the selected value by (after injection of lookupfield);
TableGroup tableGroup = (TableGroup) LUFTableGroup.getValue();

Full example code (used [] brackets instead of angled);
[data]
[collection id=“tableGroupDc” class=“com.jsonedi.jediadmin.entity.TableGroup” view="_local"]
[loader id=“tableGroupDl”]
[query][![CDATA[select e from jediadmin_TableGroup e]]][/query]
[/loader]
[/collection]
[instance id=“tableGroupId” class=“com.jsonedi.jediadmin.entity.TableGroup”/]
[/data]
[layout]
[lookupField id=“LUFTableGroup” optionsContainer=“tableGroupDc” captionProperty=“tGName” dataContainer=“tableGroupId” property=“tGName”/]
[/layout]

@Inject
private LookupField LUFTableGroup;
@Subscribe("BtnStep1Next")
public void onBtnStep1NextClick(Button.ClickEvent event) {
    TableGroup tableGroup = (TableGroup) LUFTableGroup.getValue();
1 Like