GenericFilter stopped working on entities related to other entities

Today I found what seems to be the issue. In my application, I’m extending both EntityPicker and EntityComboBox to achieve the behavior I explained in this post EntityComboBox with entity_open and readOnly=true.

Well, it seems that if I extend only one of them, filters work fine; but when both of them are extended, filters stop working. Both extended component’s classes are the same:

public class EntityPickerDetail<E> extends EntityPicker<E> {

    private Button detailBtn;
    private EntityOpenAction<E> openAction;
    private EntityLookupAction<E> lookupAction;

    private boolean sinEdit = false;

    @Override
    public void afterPropertiesSet() {
        super.afterPropertiesSet();

        addOpenAndLookupActions();
        initDetailBtn();
        setPrefixComponent(detailBtn);
    }

    private void addOpenAndLookupActions() {
        DialogWindows dialogWindows = applicationContext.getBean(DialogWindows.class);

        openAction = new EntityOpenAction<>();
        openAction.setDialogWindows(dialogWindows);
        openAction.setIcon(LumoIcon.EDIT.create());
        addAction(openAction);

        lookupAction = new EntityLookupAction<>();
        lookupAction.setDialogWindows(dialogWindows);
        lookupAction.setIcon(LumoIcon.SEARCH.create());
        addAction(lookupAction);
    }

    private void initDetailBtn() {
        detailBtn = applicationContext.getBean(UiComponents.class).create(Button.class);
        detailBtn.setIcon(LumoIcon.EDIT.create());
        detailBtn.addThemeVariants(ButtonVariant.LUMO_ICON, ButtonVariant.LUMO_TERTIARY_INLINE);
        detailBtn.setVisible(false);

        detailBtn.addClickListener(clickEvent -> openAction.execute());
    }

    @Override
    public void setReadOnly(boolean readOnly) {
        super.setReadOnly(readOnly);
        detailBtn.setVisible(readOnly && !isEmpty());
    }


    @Override
    public void setValue(E value) {
        super.setValue(value);
        if (detailBtn != null)
            detailBtn.setVisible(!sinEdit && isReadOnly() && value != null);
        if (openAction != null)
            openAction.setVisible(!sinEdit && value != null);
    }

    @Override
    public void addClassName(String className) {
        super.addClassName(className);
        switch (className) {
            case "sin_lookup" -> lookupAction.setVisible(false);
            case "sin_edit" -> {
                sinEdit = true;
                detailBtn.setVisible(false);
                openAction.setVisible(false);
            }
        }
    }
}

Then they are registered like this:

    @Bean
    public ComponentRegistration comboBoxDetail() {
        return ComponentRegistrationBuilder.create(ComboBoxDetail.class)
                .replaceComponent(EntityComboBox.class)
                .build();
    }

    @Bean
    public ComponentRegistration entityPickerDetail() {
        return ComponentRegistrationBuilder.create(EntityPickerDetail.class)
                .replaceComponent(EntityPicker.class)
                .build();
    }

I hope you can tell me what am I doing wrong, or if there is a better way to achieve the same goal (entity_open action visible wether readOnly is true or false)

1 Like