fieldGroup with lookupField

Hello,

I’m trying to add lookupField in the fieldGroup but I get nothing when I set the optionsList to the lookupField.

XML:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://editorCaption"
        class="com.company.myProject.web.annotation.AnnotationEdit"
        datasource="annotationsDs"
        focusComponent="fieldGroup_1"
        messagesPack="com.company.myProject.web.annotation">
    <dsContext>
        <collectionDatasource id="annotationsDs"
                              class="com.company.myProject.entity.Annotation"
                              loadDynamicAttributes="true"
                              view="_local">
            <query>
                <!&#91;CDATA&#91;select e from myProject$Annotation e&#93;&#93;>
                <filter>
                    <and>
                        <c>e.adSpace = :component$lookupField</c>
                    </and>
                </filter>
            </query>
        </collectionDatasource>
    </dsContext>
    <dialogMode height="600"
                width="800"/>
    <layout expand="split"
            spacing="true">
        <split id="split"
               orientation="vertical"
               width="100%">
            <fieldGroup id="fieldGroup_1"
                        datasource="annotationsDs">
                <column width="250px">
                    <field custom="true"
                           property="adSpace"
                           required="true"
                            />
                    <field property="type"/>
                    <field property="code"/>
                    <field property="isBestselling"/>
                    <field property="created"/>
                    <field property="enabled"/>
                    <field property="updated"/>
                    <field property="id"/>
                </column>
            </fieldGroup>
        </split>
        <frame id="windowActions"
               screen="editWindowActions"/>
    </layout>
</window>

AbstractEditor:


@Override
public void init(Map<String, Object> params) {

    lookupField = componentsFactory.createComponent(LookupField.class);

    Collection<Annotation> annotationCollection = annotationsDs.getItems();
    if(CollectionUtils.isNotEmpty(annotationCollection)) {

        adSpaceString = annotationCollection.stream()
                .map(Annotation::getAdSpace)
                .distinct()
                .collect(Collectors.toList());

        lookupField.setOptionsList(adSpaceString);

    }

    fieldGroup_1.getFieldNN("adSpace").setComponent(lookupField);
}

The same approach works in the browser screen but not in the editor screen.
Please let me know if I’m missing something.

Thanks

Honestly, I hardly understand what you are going to implement. The editor screen is designed for working with a single entity record, and you are using the collectionDatasource in it.
Could you explain your idea of this lookupField?

Hi Olga,

I just need to populate the lookup field in the editor screen.
The list of options should come from the db.
How can I achieve this…

There is no difference where you populate the lookupField. The main point is the datasource you use: the simple datasource for the single entity instance is used as the main datasource in edit screens, the collectionDatasource is used to work with a collection of entity instances.
Thus, you can use a lookupField to set some entity attribute in the edit screen, and for this purpose you set the datasource attribute with its property to the lookupField. In order to populate the lookupField with some options, you set the optionsDatasource or an options list, whatever, but this cannot be the same datasource that returns the edited entity instance.
See the examples in the documentation and Sampler.