Create frame dynamically by screen Id

Hello,
first thanks again for your great support in this forum.
My question: I want to create a frame dynamically by its screen Id and add it to a tab. How can I instantiate a frame? The following code didn’t work since the screen class of a AbstractFrame is null.

AbstractFrame frame = (AbstractFrame)windowConfig.getWindowInfo(screenId).getScreenClass().newInstance()

Hi Stefan,
Use openFrame() method which is available in any screen controller. See an example here: sample-akkount/OperationEdit.java at master · cuba-platform/sample-akkount · GitHub

This works, thanks a lot. I want to add also the tab dynamically. Since the addTab method requires a child component as parameter and the openFrame method requires a parent component as parameter, I used following workaround to create a tab and add a frame to it:


VBoxLayout box = componentsFactory.createComponent(VBoxLayout.class);
TabSheet.Tab tab = tabSheet.addTab(tabId ,box);
 AbstractFrame frame = openFrame(box, frameId, null);

Is there a solution without the additional Layout component?

You can invoke openFrame() with null as parent (see JavaDocs). After that, try to add the frame to the TabSheet directly. Please report if it doesn’t work.

Sorry, I thought I tried this and it was not working. But its working now.

openFrame() can be invoked with null as parent. Thank you.