Trying to create tabs in Vaadin Flow v24 , managed by separate Java class files and following this elegant solution about Tabs in tab Vaadin Flow java , I implemented this sample code :
private Map<Tab, RouterLink> tabSheets = new HashMap<>();
private Tabs mainTabs;
private Tabs getTabs() {
Tab tab1 = new Tab(VaadinIcon.EYE.create(), new Span("Tab 1"));
Tab tab2 = new Tab(VaadinIcon.COG.create(), new Span("Tab 2"));
tabSheets.put(tab1, new RouterLink("artab1", ARTab1.class) ); /* which is in a separate java class file */
tabSheets.put(tab2, new RouterLink("artab1", ARTab2.class) ); /* which is in a separate java class file */
Tabs tabsToAdd = new Tabs(tabSheets.keySet().toArray(new Tab[]{}));
tabsToAdd.addThemeVariants(TabsVariant.LUMO_EQUAL_WIDTH_TABS);
tabsToAdd.setMaxWidth("100%");
tabsToAdd.setWidthFull();
}
public MainView() {
mainTabs = getTabs();
UI.getCurrent().navigate(ARDevices.class);
mainTabs.addSelectedChangeListener(e -> UI.getCurrent().navigate(tabSheets.get(e.getSelectedTab()).getClass()));
add(mainTabs);
}
where ARTab1.class and ARTab2.class are managed in separate files like :
@Route(value="artab1", layout = MainView.class)
public class ARTab1 extends VerticalLayout {
public ARTab1() {...}
}
It doesn’t produce any errors but when I select a tab on the browser I see like this:
Could not navigate to ''
Available routes:
<root>
artab1
artab2
This detailed message is only shown when running in development mode.
but this piece of code:
mainTabs.addSelectedChangeListener(e -> UI.getCurrent().navigate(tabSheets.get(e.getSelectedTab()).getClass()));
should let me navigate and so load the class and even appear on the URL the label of the class due of getting the class of selected tab; but it happens only if I click on one of those links I see on that Couldn't not navigate to ''
…
I thought it could be because there wasn’t the ParentLayout pointing to MainView.class as in the other question said to have a relation to the main view but if I add that ParentLayout then the localhost webserver doesn’t even run and crashes.
Maybe I missed something? Or could it be due to the version of Vaadin which I’m using v24 ?
Thanks in advance to all!
Cheers!