Set the text for viewTitle on main-view.xml

Hi,
I noticed that on the main-view.xml there are these lines

<header id="header" classNames="jmix-main-view-header">
                <drawerToggle id="drawerToggle"
                              classNames="jmix-main-view-drawer-toggle"
                              themeNames="contrast"
                              ariaLabel="msg://drawerToggle.ariaLabel"/>
                <h1 id="viewTitle" classNames="jmix-main-view-title"/>
            </header>

I noticed that the viewTitle is dynamically changed by by each view based on the view title.
I wants to set the main view viewTitle as Dashboard but

                <h1 id="viewTitle" classNames="jmix-main-view-title" text="Dashboard"/>

does not work. Can you help me understand how does this viewTitle changes and how to set its default text (text in main-view page) as Dashboard?
Thank you.

Hi!

The Title for MainView is not set declaratively using XML, but rather programmatically in the StandardMainView class.

If you open it, you can see the Title setting code:

    protected void updateTitle() {
        getTitleComponent()
                .filter(c -> c instanceof HasText)
                .ifPresent(c -> ((HasText) c).setText(getTitleFromOpenedView()));
    }

    protected String getTitleFromOpenedView() {
        return ViewControllerUtils.getPageTitle(getContent().getContent());
    }

The updateTitle() method is called every time a new view is opened. So this code overwrites the value you are trying to set using XML.

So, you need to override the super getTitleFromOpenedView() method for your MainView class:

    @Override
    protected String getTitleFromOpenedView() {
        String superTitle = super.getTitleFromOpenedView();
        return Strings.isNullOrEmpty(superTitle) ? "Dashboard" : superTitle;
    }

Best regards,
Dmitriy