I have a screen that programmatically opens a new screen with a screen-id in a new tab. However, if the screen id is already opened, I want to close that and open a new one with new data. How do I do this ?
Hello,
You can try to close opened screen like this:
String screenId = "app_MyScreen";
Collection<Screens.WindowStack> windowStacks = screens.getOpenedScreens().getWorkAreaStacks();
for (Screens.WindowStack windowStack : windowStacks) {
Collection<Screen> screens = windowStack.getBreadcrumbs();
for (Screen screen : screens) {
if (screen.getId().equals(screenId)) {
screen.close(StandardOutcome.CLOSE);
return;
}
}
}
Note, if your screen presents in the Breadcrumbs but is not visible, the screen won’t be closed. In this case, you will have to close all previous screens in the breadcrumbs too.
1 Like