Lookup Field choose particular values

Hello,

I have a One-to-One relation between two entities and I use a Lookup Field in order to select the appropriate rows. The problem is that I have an enumeration field and the user should can choose only particular values (see below).

   <query>
        <![CDATA[select e from abc_Customer e where e.test = 'A' ]]>
    </query>

This works for the first button (arrow) but if I press “Open a lookup screen button” the user can see whole table.
image

Please advise!

-n

To be more precisely it’s about a LookupPickerField and lookup action.
image

Hello @neutrino,

To solve your problem you need to take two steps:

  1. Override the default picker_lookup action behavior to pass a specific parameter “testValue” to CustomerBrowse screen. You can find an example of use in the documentation
    @Inject
    private ScreenBuilders screenBuilders;
    @Inject
    private LookupPickerField<Customer> customerField;

    @Subscribe("customerField.lookup")
    public void onCustomerFieldLookup(Action.ActionPerformedEvent event) {
        screenBuilders.lookup(Customer.class, this)
                .withField(customerField)
                .withScreenClass(CustomerBrowse.class)
                .withOptions(new MapScreenOptions(
                        ParamsMap.of("testValue", "A")))
                .build()
                .show();
    }
  1. Delegate data loading to customersDlLoadDelegate function in CustomerBrowse. If the “testValue” parameter is passed, then it is taken into account when loading data. You can find an example of use in the documentation
public class CustomerBrowse extends StandardLookup<Customer> {

    @WindowParam
    private String testValue;

    @Inject
    private DataManager dataManager;

    @Install(to = "customersDl", target = Target.DATA_LOADER)
    private List<Customer> customersDlLoadDelegate(LoadContext<Customer> loadContext) {
        if (testValue != null) {
            loadContext = loadContext.setQuery(
                    LoadContext.createQuery("select e from abc_Customer e where e.test = :testValue")
                            .setParameter("testValue", testValue));
        }
        return dataManager.loadList(loadContext);
    }
}

Regards,
Gleb

1 Like

Gleb you are the best!
Thank you!

Can you explain a little bit when should I use Install Delegate?
This chapter is kind of “twilight zone” for me.

Best Regards,
-n

Hi @neutrino,

Using delegates, you can provide code that will be used by various screen mechanisms instead of their standard implementations. For example, you can provide your own function to load data or to set the row icon provider for the table and much more.
You can see the entire list of delegates for the screen controller in the Install Delegate tab using the CUBA Studio.

image

Each delegate in the window is provided with a description on the right which is extracted from the framework Javadocs.

Regards,
Gleb

1 Like