Using Value Datasource with LookupField

Hi,
I have a Lookup Field on the screen based on Value Datasource.

        <valueCollectionDatasource id="YearDs">
            <query>
                <!&#91;CDATA&#91;select distinct o.year from demo$Order o&#93;&#93;>
            </query>
            <properties>
                <property datatype="int"
                          name="year"/>
            </properties>
        </valueCollectionDatasource>
                
        ...
        
        <lookupField optionsDatasource="YearDs"/>

I don’t know how to configure Lookup field to show the ‘year’ property instead of sys$KeyValueEntity-?(…)

Hi,
OptionsDatasource of LookupFiled returns a list of entities. So that is why you see the list of sys$KeyValueEntity.
You can manually fill options list of the LookupField. For instance, as I do in the following code.
See the documentation for more information about DataManager.

public class DemoEdit extends AbstractEditor<Demo> {

    @Inject
    private LookupField lkpField;

    @Inject
    private DataManager dataManager;

    @Override
    public void init(Map<String, Object> params) {
        List<Integer> options = new ArrayList<>();

        String queryString = "select distinct o.year from demo$Order o";

        ValueLoadContext valueLoadContextontext = ValueLoadContext.create()
                .setQuery(ValueLoadContext.createQuery(queryString));
        valueLoadContextontext.addProperty("year");
        List<KeyValueEntity>  resultList = dataManager.loadValues(valueLoadContextontext);

        for(KeyValueEntity entry : resultList){
            options.add((Integer)entry.getValue("year"));
        }
                
        lkpField.setOptionsList(options);
        super.init(params);
    }
}

And there is a simple way. Just set captionProperty - “year”.


<lookupField id="lkpField"
             captionProperty="year"
             datasource="demoDs"
             optionsDatasource="yearDs"
             property="orderLink"/>

Rostislav,
Thank you. That works.