Studio: Setting up a SearchPickerField in a field group

Within Cuba - Studio, setting up a lookup field or picker field is very straight forward via the GUI.

I have been looking into setting up SearchPickerField in a fieldgroup

The documentation seems to indicate this is possible, but it is not clear to me how show this component from within Studio
https://doc.cuba-platform.com/manual-6.3/gui_FieldGroup.html

I have tried adding the following WHERE clause to the collection datasource but this did not seem to work.

sql
where e.name like :(?i)custom$searchString

Any help/advice would be appreciated.

Hi,

Now, automatic creation of SearchPickerField is not supported by FieldGroup, it can be added only as custom field from a screen controller.

Example XML:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://editCaption"
        class="com.company.demo.web.purchase.PurchaseEdit"
        datasource="purchaseDs"
        focusComponent="fieldGroup"
        messagesPack="com.company.demo.web.purchase">
    
    <dsContext>
        <datasource id="purchaseDs"
                    class="com.company.demo.entity.Purchase"
                    view="purchase-view"></datasource>
        <collectionDatasource id="clientsDs"
                              class="com.company.demo.entity.Client"
                              view="_minimal">
            <query>
                <![CDATA[select e from spfield$Client e where e.name like :(?i)custom$searchString]]>
            </query>
        </collectionDatasource>
    </dsContext>

    <layout expand="windowActions"
            spacing="true">
        <fieldGroup id="fieldGroup"
                    datasource="purchaseDs">
            <column width="250px">
                <field id="title"></field>
                <field id="client" generator="generateClientField"></field>
            </column>
        </fieldGroup>
        <frame id="windowActions"
               screen="editWindowActions"></frame>
    </layout>
</window>

Here we set generator attribute that is pointing to the method of the screen controller:


public class PurchaseEdit extends AbstractEditor<Purchase> {
    @Inject
    private ComponentsFactory componentsFactory;

    @Inject
    private CollectionDatasource<Client, UUID> clientsDs;

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

    public Component generateClientField(Datasource datasource, String property) {
        SearchPickerField searchPickerField = componentsFactory.createComponent(SearchPickerField.class);
        searchPickerField.setDatasource(datasource, property);
        searchPickerField.setOptionsDatasource(clientsDs);

        searchPickerField.addLookupAction();
        searchPickerField.addClearAction();

        return searchPickerField;
    }
}

And we will see SeachPickerField in the FieldGroup:

search-picker

1 Like

Thanks for the example!

I was trying to resolve the same problem.
Following the example, all works perfectly. Thank you!