LookupField with CustomCollectionDatasource problem

Hi,

I need help with the integration of LookupField with the CustomCollectionDatasource.
If I set optionsDatasource to the CustomCollectionDatasource, LookupField does not get data from it when I entering text (the getEntities method is not executed or executed only once if refreshMode=“NEVER” is not set).

My custom datasource:

public class ExternalDocumentsDatasource extends CustomCollectionDatasource<ExternalDocument, String> {

    @Override
    protected Collection<ExternalDocument> getEntities(Map<String, Object> params) {
        return myService.getData(params)
    }
}

XML

   <collectionDatasource id="externalDocumentsDs"
                          class="com.company.transport.entity.ExternalDocument"           datasourceClass="com.company.transport.web.transportpackage.ExternalDocumentsDatasource"
                          refreshMode="NEVER"/>


                    <lookupField id="externalDocumentField"
                                 datasource="transportPackageDs"
                                 optionsDatasource="externalDocumentsDs"
                                 property="externalDocument"
                                 width="100%"/>

Regards
Marcin

Hi Marcin!

If you set refreshMode NEVER, the datasource will not load data at all.
So, after you remove NEVER, your datasource will load data at start, and if you want it to reload data, manually invoke externalDocumentsDs.refresh().

Hi Alexander.

I know about this. But I need refresh datasource (reading filtered items) when I entering text into field.
Something like this: entering text -> LookupField invoke method getEntities() with search string

Try something like

externalDocumentField.setNewOptionAllowed(true);
externalDocumentField.setNewOptionHandler(caption -> {
    externalDocumentsDs.setSearchString(caption);
    externalDocumentsDs.refresh();   
});

Hey,

Thank you. But I think that this is not a good solution, because it worked only when I pressed the Enter key.
I replaced LookupField by SuggestionField.

Marcin