Can not dynamically set tabsheet sheet caption

setting a tab sheet caption from code doesnt seem to be working. I tried both in the beforeShowEvent and AfterShowEvent. Nnote that Im using a fragment but I don’t expect this to be an issue, with a debugger I can see the code being executed.


    @Named("tabsheet.myTab")
    private VBoxLayout myTab;

    @Subscribe(target = Target.PARENT_CONTROLLER)
    private void onAfterShowHost(Screen.AfterShowEvent event) {
        myTab.setCaption("Some caption");
    }

    @Subscribe(target = Target.PARENT_CONTROLLER)
    private void onBeforeShowHost(Screen.BeforeShowEvent event) {
        myTab.setCaption("does this work?");
    }

Hi.

Pay attention that you inject VBoxLayout component which represents tab layout.
You need to inject the TabSheet component instead of VBoxLayout component and reach the Tab component using TabSheet methods.

@Inject
    private com.haulmont.cuba.gui.components.TabSheet TabSheet;

    @Subscribe
    public void onBeforeShow(BeforeShowEvent event) {
        TabSheet.getTab("tab").setCaption("Main");
    }

Regards,
Natalia

Aha, I see. I had the tab injected through the gui editor “inject to component controller” so assumed it was correct.

thanks for the solution.