LookupField in fieldgroup

Hi,
How to create a lookup field in fieldgroup? I added a testtype lookupfield into fieldgroup but this field doesn’t show on the editor screen.

<dsContext>
        <datasource id="testdefDs"
                    class="com.company.mastert.entity.Testdef"
                    view="_local"/>
        <collectionDatasource id="UDCDs"
                              allowCommit="false"
                              class="com.company.mastert.entity.UDC"
                              view="_local">
            <query>
                <![CDATA[SELECT TOP 1000 UDCKEY,UDCVALUE,LOCALVAL FROM UDC WHERE UDCTYPE = 'TESTTYPE']]>
            </query>
        </collectionDatasource>
    </dsContext>
    <dialogMode height="600"
                width="800"/>
    <layout expand="scrollBox"
            spacing="true">
        <scrollBox id="scrollBox"
                   spacing="true">
            <fieldGroup id="fieldGroup"
                        datasource="testdefDs">
                <column width="250px">
                    <lookupField datasource="testdefDs"
                        property="testtype"
                        optionsDatasource="UDCDs"/>
                    <field property="testname1"/>
                    <field property="testname2"/>
                    <field property="udctype"/>
                    <field property="udckey"/>
                    <field property="isnum"/>
                    <field property="alwmin"/>
                    <field property="premin"/>
                    <field property="target"/>
                    <field property="premax"/>
                    <field property="alwmax"/>
                </column>
            </fieldGroup>
        </scrollBox>
        <frame id="windowActions"
               screen="editWindowActions"/>
    </layout>

Hi Thomaslei,

you don’t need to define the lookupfield in this way. You can just set a ‘field’ and add (as you already did) the optionsDatasource attribute - that’s enough.
(one more thing - if you already define the datasource for the fieldGroup, you don’t need to set it on each field, this is also valid for the field which will automatically ‘transform’ to a lookup field).

Only drawback with this ‘automated’ generated lookupfield in a fieldGroup is, that you can’t easily use so much of the advanced features of the lookupfield (https://doc.cuba-platform.com/manual-6.9/gui_LookupField.html)

Please take a lookup on the getComponent() description to see what visaul component will be generated for the different combinations of attributes of a field.
FieldGroup

CU
Steven

1 Like

Hi,
I want to add a filter to the collectionDatasource “UDCDs” but the filter doesn’t work.

<dsContext>
        <datasource id="testdefDs"
                    class="com.company.mastert.entity.Testdef"
                    view="_local"/>
        <collectionDatasource id="UDCDs"
                              allowCommit="false"
                              class="com.company.mastert.entity.UDC"
                              view="_local">
            <query>
                <![CDATA[SELECT e FROM mastert$UDC]]>
                <filter>
		        <and>
			        <c>e.udctype = "TESTTYPE"</c>
		        </and>
	            </filter>
            </query>
        </collectionDatasource>
    </dsContext>
    <dialogMode height="600"
                width="800"/>
    <layout expand="scrollBox"
            spacing="true">
        <scrollBox id="scrollBox"
                   spacing="true">
            <fieldGroup id="fieldGroup"
                        datasource="testdefDs">
                <column width="250px">
                    <field optionaldatasource="UDCDs"
                           property="testtype"/>

Hi,

Try “select e from mastert$UDC e“ - that might be the problem…

Bye
Mario

I changed it to SELECT e FROM mastert$UDC e but doesn’t work.

        <collectionDatasource id="UDCDs"
                              allowCommit="false"
                              class="com.company.mastert.entity.UDC"
                              view="_local">
            <query>
                <![CDATA[SELECT e FROM mastert$UDC e]]>
                <filter>
                    <and>
                        <c>e.udctype = "TESTTYPE"</c>
                    </and>
                </filter>
            </query>
        </collectionDatasource>

It is:

<field optionsDatasource="UDCDs"
                            property="testtype"/>

not:

<field optionaldatasource="UDCDs"
                           property="testtype"/>

Try to either configure it via studio through the UI or directly via IntelliJ IDEA, because both ways will tell you that you did a typo…

Docs reference: https://doc.cuba-platform.com/manual-6.9/gui_FieldGroup.html#gui_FieldGroup_field_datasource

Bye
Mario

1 Like

Hi Mario,
Thank you very much. I fixed it. It works in the dropdown list. But I need the lookup to filter the data as well. I added a LookupPickerField in controller and a lookupaction to this field. But no filter for this lookup. How can I do it?

<dsContext>
        <datasource id="testdefDs"
                    class="com.company.mastert.entity.Testdef"
                    view="_local"/>
        <collectionDatasource id="UDCDs"
                              allowCommit="false"
                              class="com.company.mastert.entity.UDC"
                              view="_local">
            <query>
                <![CDATA[SELECT e FROM mastert$UDC e]]>
                <filter>
                    <and>
                        <c>e.udctype = 'TESTTYPE'</c>
                    </and>
                </filter>
            </query>
        </collectionDatasource>
    </dsContext>
    <dialogMode height="600"
                width="800"/>
    <layout expand="scrollBox"
            spacing="true">
        <scrollBox id="scrollBox"
                   spacing="true">
            <fieldGroup id="fieldGroup"
                        datasource="testdefDs">
                <column width="250px">
                    <field optionsDatasource="UDCDs" property="testtype"/>
    @Named("fieldGroup.testtype")
    protected LookupPickerField testtypeField;

    @Override
    public void init(Map<String, Object> params) {
        testtypeField.addLookupAction();
    }

lookupaction