Editable browse and LookupPickerField component

Hi

I’d like change window related to LookupPickerField. In edit controller I can to invoke method setLookupScreen in LookupAction, but in editable browse I don’t have access to lookupPickerField.
How can I do it in editable browse ?

Hi!

Could you clarify your question? Do you want to get access to LookupPickerField from opened LookupScreen?

To transfer parameters to the screen, you should use setLookupScreenParams() in LookupAction. And in the init() method of LookupScreen get objects from a map. Also, you can inject transferred parameters using @WindowParam annotation (see documentation).

Set params to the LookupScreen:

@Inject
private LookupPickerField lookupPickerField;

@Override
public void init(Map<String, Object> params) {
    PickerField.LookupAction lookupAction = lookupPickerField.getLookupAction();
    lookupAction.setLookupScreenParams(ParamsMap.of("lookup", lookupPickerField));
}

Opened browse screen:

@WindowParam(name = "lookup")
protected LookupPickerField lookupPickerField;

@Override
public void init(Map<String, Object> params) {
    if (lookupPickerField != null) {
        showNotification(lookupPickerField.getId());
    }
}

Not exactly. I have composition and brwose with LookupPickerField is inner editwindow. I set column with LookupPickerField as editable in this browse, but I don’t have access to this field because in composition I haven’t browse controler. Look at this screen. I have marked LookupPickerField this screenshot.

obraz

Unfortunately, we can’t get access to the field in the editable column, cause it was generated. If you use Platform 6.8.0+, as a possible option, you can do your own generation component strategy. See documentation.
You will be able to create component depending on Entity, property, component class and others. You should create spring bean and implements ComponentGenerationStrategy and spring Ordered interface.

Code example:

@Nullable
@Override
public Component createComponent(ComponentGenerationContext context) {
    String property = context.getProperty();
    MetaClass orderMetaClass = metadata.getClassNN(Order.class);
    if (orderMetaClass.equals(context.getMetaClass())
            && "customer".equals(property)
            && context.getComponentClass() != null
            && Table.class.isAssignableFrom(context.getComponentClass())) {

        PickerField pickerField = factory.createComponent(PickerField.class);
        pickerField.setDatasource(context.getDatasource(), property);

        pickerField.addOpenAction();

        PickerField.LookupAction lookupAction = pickerField.addLookupAction();
        lookupAction.setLookupScreen("strategysample$Customer.browse");
        return pickerField;
    }
    return null;
}

Sample project:strategy-sample.zip (82.5 KB)

1 Like

ok
I create class like in this example.
Could you expain me how I can use this custom component in project ?

Following the example above, given component will be generated in an editable column of a table for certain Entity property instead of default component. This method allows us to customize the generated component as we want.

You are great ! Thanks
Can I create many class like this in project e.g for each entity ?

Sure, you can. If there are still questions, please ask!

Thanks.

I had some problem with refreshing browse. I describe my problem in topic

In window from this topic I have same problem. I try to use datasources listeners, but there is problem with transaction while accept window.