Picker Field Lookup Action default OpenType

Hi,

i’ve a question about the PickerField component. What i want to change it the default open type of the LookupAction to DIALOG instead of THIS_TAB. to achieve this, i thought of the following possibilities:

  1. change the browse screens with the DIALOG mode in the XML browse definitions with this snippet:
  2. change the open type programmatically in the screen with the PickerField
  3. extend the WebPickerField with a custom class and register it as the default PickerField class (how would i exactly do that?)

Besides the possibilities to do this on my own my question would be if it is possible (and makes sense) to make this setting configurable. What do you think?

Bye,
Mario

Hi Mario,

Now you can customize a LookupAction only on the screen level - either in XML using openType=“DIALOG” attribute, or programmatically in the controller. Changing the lookup action globally on the project level is hardly possible, the same as for other standard actions. I think it is a shortcoming, and we should provide a simple way to create own implementations of standard actions. Making a configuration parameter just for one particular action would be too partial solution.

Hi Konstantin,

this sounds reasonable. But would the third approach not fulfill the needs? Although it is questionable if this is a good idea to extend the FW in such a way.

Another thing that came to my mind is that i can use the lookup screen xml and adjust the settings in the every ${entity}-lookup.xml file. This works with the minor downside that changes in the browser screen for an entity has to be copied to the lookup screen. But one major drawback is that i can’t get studio to create an additional lookup screen file (anymore?! - i’m not really sure).

Is the ${entity}-lookup.xml mechanism a thing that is deprecated or why is there not much information about it in studio and or in the docs?

Bye,
Mario

Hi Mario,

You can override the default implementation of PickerField as follows:

  • Create a class extending WebPickerField:

public class MyWebPickerField extends WebPickerField {

    @Override
    public LookupAction addLookupAction() {
        LookupAction action = new LookupAction(this);
        action.setLookupScreenOpenType(WindowManager.OpenType.DIALOG);
        addAction(action);
        return action;
    }
}
  • Create the web-ui-components.xml file in the root package of your project:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<components>
    <component>
        <!-- see PickerField.NAME constant -->
        <name>pickerField</name>
        <!-- Default XML loader -->
        <componentLoader>com.haulmont.cuba.gui.xml.layout.loaders.PickerFieldLoader</componentLoader>
        <!-- Your implementation -->
        <class>com.company.sample.web.components.MyWebPickerField</class>
    </component>
</components>
  • In web-app.properties, define a property to process your component registration file:

cuba.web.componentsConfig = +com/company/sample/web-ui-components.xml

That’s all, your custom MyWebPickerField will be used instead of default WebPickerField. See the whole project here: https://github.com/knstvk/cuba-sample-web-component

Regarding multiple lookup screens for an entity: you can create as many screens of any type as you want, but the standard LookupAction will use by default first a screen with {entityName}.lookup id, if it is not found - {entityName}.browse. If you create an additional lookup screen with a different id, you have to specify this id using LookupAction.setLookupScreen() method.

1 Like

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-8235

Hi,
I have a pickerfield, and I set opentype to , but it does not work…

<pickerField id="code_group" openType="DIALOG" metaClass="sec$Group" />

I set it to NEW_TAB, still does not work. Always THIS_TAB behavior…

Any suggestions?