Custom component and events

I have a custom component which is a CompositeComponent.

@CompositeDescriptor("master-data-combo-box.xml")
class MasterDataComboBox :
    CompositeComponent<CssLayout>(),
    Field<BaseMasterData>,
    CompositeWithCaption,
    CompositeWithHtmlCaption,
    CompositeWithHtmlDescription,
    CompositeWithIcon,
    CompositeWithContextHelp,
    Focusable, Logging {
    init {
        addCreateListener {
            radioButtonBox = getInnerComponent("radioButtonBox")
            radioButton = getInnerComponent("radioButton")
            cleanButton = getInnerComponent("cleanButton")
            newButton = getInnerComponent("newButton")
            entityComboBox = getInnerComponent("entityComboBox")
            availableEntitySelectors = listOf(radioButton, entityComboBox)
            // Set entityComboBox as the default component. We need it during initialisation.
            actualEntitySelector = entityComboBox

            // clean button for radioButton
            cleanButton.addClickListener { value = null }
            newButton.addClickListener { createNewItem() }
        }
        addAttachListener {
            if (isVisible) initialize()
            else shouldBeInitialized = true
        }
    }

I would like to initialize() not during attach event but during onBeforeShow event.

How to do this ?

Hi!

A composite component has only two types of listeners:

  • Attach
  • Detach

onBeforeShow event is available only for views. Why do you need onBeforeShow?
What Jmix version are you using?
Perhaps the concept of fragments would be more suitable for your task?

Regards,
Dmitriy