Filling custom field on edit screen when entity is selected in entity browser

Hi there.

I have a mixed screen with entity list at left and entity editor at right.
I have a custom readonly field that i need to fill based on selected entity (request to be done in DB in order to show its value) but can not figure out what event to use to set that value at this precise moment.
Thanks for any input !

Hello @IO_libre

Just keep a reference to editor and invoke its custom method when entity is selected in browser.

Regards

Hi Daniil.
Thanks for your input. Its conciseness makes me think that i miss obvious elements but i unfortunately can not see which ones.
From what i understood i should start by adding an event listener to selection in the browser, which i believe i would find. However, the remaining operations look mysterious to me. I have been looking for instances of editor or editor classes and places where i could gather them, without luck yet. Could you please expand a bit on this?

Thanks a lot.

Hi,

Could you share sample project to understand how your custom screens are implemented?

Sure. I’ll be creating a sample project asap.
Thanks.

I created a light sample project. There are two entities and a screen. The screen shows second entity browser and editor. The editor has a custom field, that is inited in the oninit() of the corresponding class.
Goal would be to update that custom field (having a request on first and unrelated entity) when an other instance is selected in browser.

Please get the project here:
https://we.tl/t-we9ool9db0

Best,

Thank you for the project.

You’re using entity combined screen (or master-detail screen) to work with entities. In this case when you select any entity in browser part, editor shows selected entity properties. To set some custom value to custom field you can subscribe for table selection and do some work:

public class SecondEntityBrowse extends EntityCombinedScreen {

    @Inject
    private UiComponents componentsFactory;
    @Inject
    private FieldGroup fieldGroup;
    @Inject
    private GroupTable<SecondEntity> table;

    private TextField<String> customField;

    @Subscribe
    protected void onInit(InitEvent event) {
        customField = componentsFactory.create(TextField.NAME);

        fieldGroup.getFieldNN("customField")
                .setComponent(this.customField);
    }

    @Subscribe("table")
    public void onTableSelection(Table.SelectionEvent<SecondEntity> event) {
        SecondEntity selected = table.getSingleSelected();
        if (selected != null) {
            customField.setValue(selected.getVariousField());
        }
    }
}

Regards

1 Like

Thanks a huge bunch.
I knew that i was missing something obvious, but i did not expect to be that.

Learned a lot today, thanks again.