I can not create a window from the Menu in DashBoardDemo Vaadin

I have a window already ready and created, using the vaadin dashboardDemo

  • The window tried to create it from the DashBoardMenu when clicking on an item.
  • But does not however does not appear the window.


https://github.com/vaadin/dashboard-demo/blob/7.7/src/main/java/com/vaadin/demo/dashboard/view/DashboardViewType.java

public enum DashboardViewType { DASHBOARD("dashboard", DashboardView.class, FontAwesome.HOME, true), //SALES("sales", SalesView.class, FontAwesome.BAR_CHART_O, false), //TRANSACTIONS("transactions", TransactionsView.class, FontAwesome.TABLE, false), //SCHEDULE("schedule", ScheduleView.class, FontAwesome.CALENDAR_O, false), SEARCH("Search by CVE ID", SearchcCVEView.class, FontAwesome.SEARCH, false), LAST("Last updated", LastUpdatedPanel.class, FontAwesome.REFRESH, false), EXPLORE("Explore", ExploreView.class, FontAwesome.COMPASS, false), ABOUT("About", AboutView.class, FontAwesome.INFO_CIRCLE, false); The AboutView.class extends from VerticalLayout and contains the window by adding it to its constructor as well UI.getCurrent (). AddWindow (about); but nothing.

@SuppressWarnings("serial")
public class AboutView extends VerticalLayout implements View {
    
    private Button createAbout = new Button("create about");
    private AboutWindow about = new AboutWindow();
    
    public AboutView() {
        setMargin(true);
        addComponent(new Label("create about"));
        
        
        UI.getCurrent().addWindow(about);
    }
    
    
     @Override
     public void enter(ViewChangeEvent event) {
        
     }
}

If in the AboutView class I create a button, if the window is created correctly

Have you tried moving the addWindow() call to the enter() method? That method gets triggered when Navigator switches views.

Separately, is there a reason to use Navigator for this purpose, aside from consistency with the other menu items in your enum? It’s not unusual to have one or two menu item buttons that have hard-coded behaviour, e.g. a logout button. If you simply attach the subwindow to the UI from whatever view is current, the user will still be at that view when the subwindow is closed.

Hi Alejandro,
But UI.getCurrent (). AddWindow (window); Inside the enter () method does not work for me,
I do not get the window

Rubén,

I tested creating a window from the enter method of a view, and it works fine for me. But let me reiterate my point before - you don’t need to create an entire view to plug into navigator if all you really want is for the new window to appear when the user clicks on the about button. Here is what I recommend:

  1. Remove ABOUT from your DashBoardViewType enum.
  2. Find the ValoMenuItemButton inner class in the
    DashboardMenu
    class… Create another class just like this one, but that takes a window on the constructor and shows the window as part of the click listener. I call is “ValoMenuItemButton2” in the snippet below.
  3. Find the
    buildMenuItems()
    method in the
    DashboardMenu
    class. After the big for-loop over
    DashboardViewType.values()
    (before
    menuItemsLayout
    is returned), create an instance of your new class and add it to the layout:
menuItemsLayout.addComponent(new ValoMenuItemButton2(new AboutWindow()));
return menuItemsLayout;

Thank you very much Alejandro C De Baca,

I worked perfectly