Hello team,
Is it possible in the platform to open a screen in a new browser tab like in standard web application?
Thanks.
Konstantin
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.
Hi Konstantin
See below, select the menu first before you right-click
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
Hi Gleb
It seems the UrlRouting API is no more exists in the recent versions of Jmix. Can you please share what would be the replacement I can use to perform generating the full url to a list view that will be emailed to users so that on-click the link can take to the page. I also want the base url is generated dynamically.
Code snippets would be appreciated.
Thanks in advance.
Hi,
Jmix 2.x doesn’t provide own API to obtain URL. It may be done using Vaadin API. For example:
View route can be obtained using RouteConfiguration
:
String url = RouteConfiguration.forSessionScope().getUrl(UserListView.class);
Note: it generates relative route, e.g. for UserListView
it returns users
.
There are different ways to get the base URL. Either ask the page what URL it currently displays and get the base part:
ui.getPage().fetchCurrentURL(url -> {...});
or ask a servlet what the last view location and also get the base part:
ui.getInternals().getActiveViewLocation();
Regards,
Gleb
Hi Gleb
Thanks.
Here is what I coded:
String url = RouteConfiguration.forSessionScope().getUrl(WorkflowListView.class);
log.info("url "+url);
String url2 = RouteConfiguration.forApplicationScope().toString();
log.info("url2 "+url2);
log.info("UI "+getUI().get().getInternals().getActiveViewLocation());
And result:
workflows
com.vaadin.flow.router.RouteConfiguration@260ec7ad
com.vaadin.flow.router.Location@66a07e51
But I am expecting something like: http://123.435.456.56:8080/myapplication/ as base url
How can I get the base URL of the application?
As I mentioned above, RouteConfiguration.forSessionScope().getUrl()
returns relative route, workflows
in your case.
Base URL can be extracted either from the java.net.URL
object or from the com.vaadin.flow.router.Location
object depending on what option you use.