Hi,
I’m trying to open entity editor in a new browser window and can’t find how to do it.
I found similar question, but the solution is already deprecated:
openWindow("sec$User.browse", WindowManager.OpenType.DIALOG.width(800).height(300).closeable(true).resizable(true).modal(false));
Also I’ve tried to use metod Screen.withOpenMode(OpenMode.NEW_WINDOW) but it doesn’t work for web.
Could you please help?
Pinyazhin
(Roman Pinyazhin)
July 29, 2020, 9:43am
#3
Hello,
since 7.0 version for opening screens you can use ScreenBuilders
bean.
@Inject
private ScreenBuilders screenBuilders;
@Subscribe("openScreenBtn")
public void onOpenScreenBtnClick(Button.ClickEvent event) {
screenBuilders.lookup(User.class, this)
.withOpenMode(OpenMode.NEW_TAB)
.show();
}
See more examples in the documentation .
It opens screen in new tab of root application screen.But I need to open entity in a new browser window or browser tab.
Pinyazhin
(Roman Pinyazhin)
July 31, 2020, 6:28am
#6
You can achieve this by using Routing API and WebBrowserTools . Add @Route
annotation to the editor screen:
@Route(value = "orders/edit", parentPrefix = "orders")
@UiController("froute_Order.edit")
@UiDescriptor("order-edit.xml")
@EditedEntityContainer("orderDc")
@LoadDataBeforeShow
public class OrderEdit extends StandardEditor<Order> {
}
In the screen from which you need to open new browser’s tab with editor screen you can do the following:
Open editor with selected entity
@Inject
private UrlRouting urlRouting;
@Inject
private WebBrowserTools webBrowserTools;
@Subscribe("newEntityBtn")
public void onNewEntityBtnClick(Button.ClickEvent event) {
String screenUrl = urlRouting.getRouteGenerator().getRoute(OrderEdit.class);
webBrowserTools.showWebPage(screenUrl + "?id=new", null);
}
Open editor to edit entity:
@Inject
private GroupTable<Order> ordersTable;
@Inject
private UrlRouting urlRouting;
@Inject
private WebBrowserTools webBrowserTools;
@Subscribe("selectedEntityBtn")
public void onSelectedEntityBtnClick(Button.ClickEvent event) {
Order selected = ordersTable.getSingleSelected();
if (selected != null) {
String screenUrl = urlRouting.getRouteGenerator().getEditorRoute(selected);
webBrowserTools.showWebPage(screenUrl, null);
}
}
Full example: froute.zip (82.1 KB)
Helpful links:
https://doc.cuba-platform.com/manual-7.2/webBrowserTools.html
https://doc.cuba-platform.com/manual-7.2/url_routes_generator.html
Also, you can check this topic: Can't open editor screen from URL - CUBA.Platform