Fragments inside lazy loaded tabs

Hi,

I am using jmix 2.3.1 and new fragment feature, but I cannot use them inside lazy loaded tabs.

First of all I never get ReadyEvent in fragment. I was able to get only Attach / Detach events.

// doesnt work
ComponentUtil.addListener(this, ReadyEvent::class.java) {
    initFragment()
}

// this event works
ComponentUtil.addListener(this, AttachEvent::class.java) {
    initFragment()
}

Then I think that there is egg-chicken problem to get components and work with them in fragment controller, because Autowiring components doesnt work in lazy loaded tabs and I need to get everything programatically by id. So I need to get special hidden component fragment id that I dont have and I dont have instance of component to get this ID. Do I understand this correctly?

// doesnt work, always uninitialized
@ViewComponent
private lateinit var someBtn: JmixButton

// what component to pass ?   
FragmentUtils.getComponentId()

// where to get id ?
UiComponentUtils.getComponent(view, id)

Thank you,
Jakub

Hi,

Thank you for reporting the problem, I’ve created a GitHub issue.

Also, pay attention that you don’t need to use any util classes to obtain component or subscribe on events:

  1. Fragment base class provides getInnerComponent() method to obtain components defined in XML.
  2. You can subscribe to any event same as in a view, e.g.:
@Subscribe
public void onReady(final ReadyEvent event) {
    Component innerComponent = getInnerComponent("root");
    ....
}

Regards,
Gleb