Vaadin 24: How to create (multiple) custom UIs

In our Vaadin8 app, we have multiple sets of views, each with their own custom UI to set up the main layout, and to provide services to the views.

In Vaadin24, I can do the layout part with @Route, but I’m not so sure about the services.
One approach is to put the services in the main layout, and call getParent() recursively to access it.
One problem with that is that when View is created, it doesn’t have a parent yet.

It seems like the old approach of having separate UIs is still the way to go, but I’m not sure where to put what.
For instance, when I try to define the UI for the servlet in web.xml, nothing happens, and I get the regular UI anyway.

What serviced do you mean?

I meant “service” as a general term. One example is just plain methods that control how a view should be rendered. Ie, the same view can render differently based on which UI it is part of. Another example is that when running in our main UI, there is a sidebar where we can log the queries we are generating. Again, all views call ((CommonUI).UI.getCurrent()).log(xxx), but only our main UI has an implementation that does anything.

In Vaadin8, since the UI and the layout already exists before I create the view, I can call these methods in a view’s constructor.

The concept of different UIs is gone (for good). The first thing that comes to mind is the usage of different MainLayout / RouterLayouts that share an common “ControllerInterface” which provides all those methods. In the beforeEnter method of the views you could get an instance of this interface by calling (findAncestor(Interface.class)) to reduce the migration to other architectures with less coupling

When the components are wired up, then I can use getParent / findAncestor. It is null in BeforeEnterObserver.beforeEnter, but you put me on the right track. Looks like AfterNavigationObserver.afterNavigation is the one to use.

( Found that by using debugger. Should’ve just read https://vaadin.com/docs/latest/routing/lifecycle )

Yeah sorry! Afternavigation it is