Page Title in Tabbed Mode

Hi Jmix Team.

I encounter page title issue in tabbed mode. I’m able to set page title in descriptor (XML) for the page title. But it is not working when we are programmatically setPageTitle() in the controller.

Below is the example of setting setPageTitle programmatically in the controller.

setPageTitle("ABC");

But the result shown on the screen as below :
{767D7971-4C3C-4BC3-913A-43D5DEC818DE}

Below is the example of setting page title in the Descriptor (XML).
<view xmlns="http://jmix.io/schema/flowui/view" title="ABC" >

But the result shown on the screen as below :
{8EC2D183-8FDB-48F9-BEF4-BD1E35DE333D}

When we are setting the pageTitle in descriptor. It is able to set the tabbed title and breadcrumbs title.
But it is unable to set breadcrumbs title when we use setPageTitle() in the controller after onBeforeShow() event And componentChangeEvent. But it is able to set the title in tabbed.

Please help to have a look. Your response is greatly appreciated — thank you!

Regards,
Chee Hao

Hi!

Thank you for your question.

This happens because the breadcrumb for the current tab is updated when the view is opened (i.e. immediately after the beforeShowEvent). If you update the pageTitle after (for example, on the onReadyEvent), then only the browser tab and mainTabsheet tab titles are updated.

I created a task to solve this problem.

I also prepared a temporary workaround. Just paste this code snippet into your view controller, which should update the pageTitle after the beforeShowEvent:

    @Override
    public void setPageTitle(String title) {
        super.setPageTitle(title);
        getCurrentViewBreadcrumb()
                .ifPresent(breadcrumb -> breadcrumb.setText(title));
    }

    private Optional<JmixBreadcrumb> getCurrentViewBreadcrumb() {
        TabViewContainer tabViewContainer = findTabViewContainer();
        if (tabViewContainer.getBreadcrumbs() != null) {
            JmixBreadcrumbs breadcrumbs = tabViewContainer.getBreadcrumbs().getContent();
            long itemsCount = breadcrumbs.getChildren().count();
            int lastIndex = Math.toIntExact(itemsCount - 1);

            return Optional.of(
                    breadcrumbs.getChildren()
                            .map(JmixBreadcrumb.class::cast)
                            .toArray(JmixBreadcrumb[]::new)[lastIndex]
            );
        }

        return Optional.empty();
    }

    private TabViewContainer findTabViewContainer() {
        Component currentComponent = getContent();

        while (currentComponent.getParent().isPresent() && !(currentComponent instanceof TabViewContainer)) {
            currentComponent = currentComponent.getParent().get();
        }

        return ((TabViewContainer) currentComponent);
    }

Best regards,
Dmitriy