【发布时间】:2015-02-05 10:25:56
【问题描述】:
如何在 Vaadin UI 的子视图之间导航。我希望网站上的标题像母版页一样保持静态,并且内容视图可以使用导航进行更改。我怎么能在 Vaadin 中做到这一点。
【问题讨论】:
标签: user-interface uinavigationcontroller vaadin
如何在 Vaadin UI 的子视图之间导航。我希望网站上的标题像母版页一样保持静态,并且内容视图可以使用导航进行更改。我怎么能在 Vaadin 中做到这一点。
【问题讨论】:
标签: user-interface uinavigationcontroller vaadin
如果您的应用程序需要支持浏览器的书签和导航(后退和前进按钮),则需要使用 URIFragments,如 book of vaadin 中所述。
使用它的一种常见方式是使用导航器:
public class NavigatorUI extends UI {
Navigator navigator;
protected static final String MAINVIEW = "main";
@Override
protected void init(VaadinRequest request) {
getPage().setTitle("Navigation Example");
// Create a navigator to control the views
navigator = new Navigator(this, this);
// Create and register the views
navigator.addView("", new StartView());
navigator.addView(MAINVIEW, new MainView());
} }
您的视图需要实现 book of vaadin 中所述的 View 接口
如果您使用 Spring,您还可以使用插件,如 SpringVaadinIntegration 或 vaadin4spring 来简化此操作,并且每个插件都有其他几个优点。
【讨论】:
您可以简单地设计您的 UI,使用标题(如果需要,还可以添加其他内容)和一个组件,该组件将充当不断变化的内容的占位符。 然后我添加一个方法来接收要显示的新内容并将其放在占位符中。 这是一些代码:
public class MyUI extends UI implements ErrorHandler {
// I usually use a layout as a place holder
private VerticalLayout content;
...
@Override
public void init(VaadinRequest request) {
...
content = new VerticalLayout();
content.setSizeFull();
final VerticalLayout layout = new VerticalLayout(header, menu, content, footer);
layout.setMargin(true);
setContent(layout);
}
public void changeContent(Component view) {
content.removeAllComponents();
content.addComponent(view);
content.setComponentAlignment(view, Alignment.MIDDLE_CENTER);
}
}
【讨论】: