Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 瓦丁弹簧导航杆_Html_Spring_Vaadin - Fatal编程技术网

Html 瓦丁弹簧导航杆

Html 瓦丁弹簧导航杆,html,spring,vaadin,Html,Spring,Vaadin,我正在尝试为Spring应用程序添加导航栏(就像bootstrap的一样),但没有让导航菜单出现在网页上 谁能告诉我这里怎么了 下面是我的代码: private Panel viewContainer; private HorizontalLayout navbar; private Button btnHome; private Button btnNested; private Button createNavigationButton(String caption, final St

我正在尝试为Spring应用程序添加导航栏(就像bootstrap的一样),但没有让导航菜单出现在网页上

谁能告诉我这里怎么了

下面是我的代码:

private Panel viewContainer;

private HorizontalLayout navbar;

private Button btnHome;
private Button btnNested;

private Button createNavigationButton(String caption, final String viewName) {
    Button button = new Button(caption);
    button.addStyleName(ValoTheme.BUTTON_SMALL);
    // If you didn't choose Java 8 when creating the project, convert this
    // to an anonymous listener class
    button.addClickListener(event -> getUI().getNavigator().navigateTo(
            viewName));
    return button;
}

@Override
protected void init(VaadinRequest request) {

    final VerticalLayout root = new VerticalLayout();
    root.setSizeFull();

    navbar = new HorizontalLayout();
    navbar.setWidth("100%");
    navbar.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
    root.addComponent(navbar);

    final Label brand = new Label("Nested demo");
    brand.addStyleName(ValoTheme.LABEL_H1);
    brand.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    navbar.addComponent(brand);
    navbar.setComponentAlignment(brand, Alignment.MIDDLE_LEFT);
    navbar.setExpandRatio(brand, 1);

    btnHome = new Button("Home", FontAwesome.HOME);
    btnHome.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    navbar.addComponent(btnHome);

    btnNested = new Button("nested", FontAwesome.COFFEE);
    btnNested.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    navbar.addComponent(btnNested);

    viewContainer = new Panel();
    viewContainer.setSizeFull();
    root.addComponent(viewContainer);
    root.setExpandRatio(viewContainer, 1);
    }
任何暗示都将不胜感激


谢谢

亨利的评论几乎肯定是正确的答案

根据init(VaadinRequest)代码判断,您使用的是UI类

没有
setContent(一些组件中有可见的内容)
你什么也看不到

在瓦丁,当你尝试新事物或做概念验证的时候,“你什么都看不到”会发生很多。我认为从真正愚蠢的UI开始总是一个好的做法,例如setContent(新标签(“TODO-实现此内容xxx”)

使用浏览器开发工具也是一个好主意。快速选择元素应该向您显示UI div为空,并允许您开始诊断

TL;DR:-

UI是一个组件容器,所以您需要-

setContent(myLayoutWithStuff);

显示一些内容。

是否只缺少导航栏?是否有任何提示(例如,浏览器的开发工具告诉你什么)?似乎setContent(root);init方法中缺少调用。
getContent().addComponent(myStuff);