Objective and setup
@Route("")
public class MainView extends AppLayout {
@Inject
public MainView(
@RouteScopeOwner(MainView.class)
WindowBean windowBean) {
menu = createMenuTabs();
addToNavbar(menu);
menu.setSelectedTab(routeTab);
page = UI.getCurrent().getPage().retrieveExtendedClientDetails(details -> {
windowBean.setWidth(details.getWindowInnerWidth());
windowBean.setHeight(details.getWindowInnerHeight());
});
}
...
@Route(value = "route", layout = MainView.class)
@PageTitle("Route")
public class RouteView extends Div implements HasUrlParameter<Long> {
@Inject
public RouteView(
@RouteScopeOwner(MainView.class)
WindowBean windowBean) {
windowWidth = windowBean.getWidth();
windowHeight =windowBean.getHeight();
}
@Override
public void setParameter(BeforeEvent event,
@OptionalParameter
Long routeId) {
page = UI.getCurrent().getPage().retrieveExtendedClientDetails(details -> {
windowBean.setWidth(details.getWindowInnerWidth());
windowBean.setHeight(details.getWindowInnerHeight());
});
...
page.addBrowserWindowResizeListener(
event1 -> {
windowHeight = event1.getHeight();
windowWidth = event1.getWidth();
buildCarousel();
});
}
private void buildCarousel() {
if (windowWidth ==0)
return;
..
}
@NormalRouteScoped
@RouteScopeOwner(MainView.class)
public class WindowBean {
.-...
}
This is the only way i found to be able to BOTH handle hotlinkink to child page AND navigation from MainPage to child.
It seems SO overly complex. All i want is to
a. Know innerWindow Size on Creation to scale image initially
b. Catch change in windowsize in order to be able to scale images
Is there a better way? I hope so.
Sidenotes:
I am using carosuel but the same is true for regular Image (that is actually is placed on the slides)
I have been following then flow and can see that the Parent Views Constructor (where the RouteScoped bean in populated)
is called very late