Is it somehow possible, to pass a dynamic param to a screen that is opened via menu item click?
i want to pass a parameter that is set within runtime and stored in main window.
A session parameter isn’t sufficient because the param should be set differently in each main window.
Hi,
The only thing I can suggest in this case is to add menu items programmatically passing desired params. In order to do this, you need to create a custom main window:
public class ExtAppMainWindow extends AppMainWindow {
@Subscribe
protected void onInit(InitEvent event) {
AppMenu.MenuItem item = mainMenu.createMenuItem("demo_NewScreen", "Test", null, menuItem -> {
Screen screen = screens.create(menuItem.getId(), OpenMode.NEW_TAB,
new MapScreenOptions(ImmutableMap.of("testParam", "testValue")));
screens.showFromNavigation(screen);
});
mainMenu.addMenuItem(item, 0);
}
}
As the result, you can handle params in screen controller:
@UiController("demo_NewScreen")
@UiDescriptor("new-screen.xml")
public class NewScreen extends Screen {
@Inject
private Label<String> info;
@Subscribe
protected void onInit(InitEvent event) {
ScreenOptions options = event.getOptions();
if (options instanceof MapScreenOptions) {
Map<String, Object> params = ((MapScreenOptions) options).getParams();
info.setValue(String.valueOf(params));
}
}
}
Also, I’ve created a GitHub issue.
In addition, there is another way of passing parameters to screens.
Regards,
Gleb
Thank you for your suggestions. I’ll see if i’ve can use one of them