Open a screen in new browser tab

Hello team,

Is it possible in the platform to open a screen in a new browser tab like in standard web application?

Thanks.
Konstantin

Right-click on the menu item and select to open in a new tab. Did you mean this or something else?

Yes, exactly. And also by using the view or edit actions in a table in a browser screen I need to be able to open the editor in a new browser tab if needed.

It works like that for which you don’t need anything to customize, did you try?

What do you mean works like that?
This is what I get on right click. I don’t have “Open in new tab”. From what I know for the platform already I don’t expect to have it. But if there is an action saying open in new browser tab it would be what I really need.
image

Hi Konstantin
See below, select the menu first before you right-click
image

BTW, this is being developed in JMIX FLOW. CUBA-PLATFORM doesn’t work this way.

Not really what I need.
Now I’m looking at the newWindowButton and wondering if its implementation may help in creating a custom edit action

Hi,

You can create a custom action that opens screens in a new Browser Tab with the help of URL Routes Generator and WebBrowserTools, e.g:

@Autowired
private GroupTable<User> usersTable;

@Autowired
private UrlRouting urlRouting;
@Autowired
private WebBrowserTools webBrowserTools;

@Subscribe("usersTable.edit")
public void onUsersTableEdit(Action.ActionPerformedEvent event) {
    User selectedUser = usersTable.getSingleSelected();
    if (selectedUser != null) {
        String routeToSelectedUser = urlRouting.getRouteGenerator()
                .getEditorRoute(selectedUser);

        webBrowserTools.showWebPage(routeToSelectedUser, ImmutableMap.of("target", "_blank"));
    }
}

Gleb

Thanks! @gorelov This is exactly what I’ve been looking for.

Is this possible for a menu item as well in the sideMenu component? I don’t see an option to add actions there…

Konstantin

Menu items can be different types, e.g.: Screen, Bean, Class, etc. See docs.

I’d recommend creating a bean, e.g.:

@UIScope
@Component("demo_MenuService")
public class MenuService {

    private UrlRouting urlRouting;
    private WebBrowserTools webBrowserTools;

    public MenuService(UrlRouting urlRouting, WebBrowserTools webBrowserTools) {
        this.urlRouting = urlRouting;
        this.webBrowserTools = webBrowserTools;
    }

    public void openUserBrowse() {
        String route = urlRouting.getRouteGenerator()
                .getRoute(UserBrowse.class);

        webBrowserTools.showWebPage(route, ImmutableMap.of("target", "_blank"));
    }
}

And use it as menu item:

<item bean="demo_MenuService" beanMethod="openUserBrowse" caption="Open Users"/>

Gleb

Yeah, well that seems handy, but it’s not what I really need.

I need to be able to open a screen in the same browser tab or in new browser tab using the same menu item and a context menu. Similar to the actions in a table.

Konstantin

Screens in Classic UI are opened only programmatically. The screens above from Mortoza Khan from Flow UI module.

In Jmix 2.0 I do not see anymore UrlRouting and WebBrowserTools has no more showWebPage method

Hi,

Instead of UrlRouting, the io.jmix.flowui.view.navigation.RouteSupport bean can be used to make it easier to work with Vaadin com.vaadin.flow.component.page.Page and com.vaadin.flow.component.page.History object.

Instead of WebBrowserTools the com.vaadin.flow.component.page.Page#open(java.lang.String, java.lang.String) can be used directly.

The Page object is obtainable from UI, e.g. Page page = UI.getCurrent().getPage()

Regards,
Gleb