Java 多页:导航器&;导航设置->&引用;组件必须在第一次调用getConnectorId()时附加到会话;
我无法在项目中运行导航器。 我总是犯错误 “首次调用getConnectorId()时,必须将组件附加到会话” 我举了几个例子,它在完全相同的设置下开箱即用,但我无法让它在我的环境中运行,我不知道为什么 这是我的主页Java 多页:导航器&;导航设置->&引用;组件必须在第一次调用getConnectorId()时附加到会话;,java,spring,gradle,vaadin,vaadin8,Java,Spring,Gradle,Vaadin,Vaadin8,我无法在项目中运行导航器。 我总是犯错误 “首次调用getConnectorId()时,必须将组件附加到会话” 我举了几个例子,它在完全相同的设置下开箱即用,但我无法让它在我的环境中运行,我不知道为什么 这是我的主页 @SpringUI public class MainUI extends UI implements View{ HorizontalLayout root; @Override protected void init(VaadinRequest request) {
@SpringUI
public class MainUI extends UI implements View{
HorizontalLayout root;
@Override
protected void init(VaadinRequest request) {
root = new HorizontalLayout();
VerticalLayout menu = this.createMenuBar();
menu.setWidth("20%");
root.addComponents(menu);
Panel viewPanel = new Panel();
root.addComponentsAndExpand(viewPanel);
setContent(root);
final Navigator navigator = new Navigator(this, viewPanel);
navigator.addView("Food", FoodView.class);
navigator.addView("Meal", MealView.class);
navigator.addView("", MainView.class);
// even with
//navigator.addView("Main", MainView.class);
//navigator.navigateTo("Main");
// i get the same error
}
@Override
public void enter(ViewChangeEvent event) {
// TODO
}
private VerticalLayout createMenuBar() {
VerticalLayout menuBar = new VerticalLayout();
for(String s: new String[] {"Food", "Meal"}) {
menuBar.addComponents(this.createNavigationButton(s, this.getNavigator()));
}
return menuBar;
}
private Button createNavigationButton(final String state, final Navigator navigator) {
return new Button("Go go" + state, new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
navigator.navigateTo(state);
}
});
}
}
这是我的主/食物/膳食视图,它们只是带有标签的树桩,因为我只想测试一个多页示例
@SpringView(name = MainView.VIEW_NAME)
public class MainView extends UI implements View {
public static final String VIEW_NAME = "Main";
@Override
protected void init(VaadinRequest request) {
VerticalLayout root = new VerticalLayout();
setContent(root);
Label lbl = new Label("MainView");
root.addComponent(lbl);
}
@Override
public void enter(ViewChangeEvent event) {
}
}
MainView
可能应该扩展VerticalLayout
(或CustomComponent
或您需要的任何内容),而不是UI
,而且我也不明白为什么你的MainUI
会实现View
,因为它有点代表而不是它的一部分。你有堆栈跟踪吗?谢谢@Morfic。你的评论让我想到了我的问题。不确定你的意思是什么