我想在vaadin中的视图之间进行导航。 我使用html和navigator创建了2个视图,但是当初始化第一个视图时,我遇到了DesignException
com.vaadin.ui.declarative.DesignException: Unable to find design file MainView.html in com.andrei
at com.vaadin.ui.declarative.Design.read(Design.java:608)
at com.andrei.MainView.<init>(MainView.java:23)
at com.andrei.MyUI.init(MyUI.java:39)
at com.vaadin.ui.UI.doInit(UI.java:770)
at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:218)
at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:76)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1601)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:445)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
我试图将html文件放在com.andrei目录中,但此方法不起作用,之后 我发现以下信息:html文件必须位于resource文件夹中,但是又不能正常工作,我必须将该文件放在哪里,或者如何将rootPath更改为目录
这是我的用户界面
@Theme("mytheme")
public class MyUI extends UI {
Navigator navigator;
protected static final String MAINVIEW = "main";
@Override
protected void init(VaadinRequest vaadinRequest) {
navigator = new Navigator(this, this);
// Create and register the views
navigator.addView("", new StartView());
navigator.addView(MAINVIEW, new MainView(navigator));
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
这是MainView:
MainView
@DesignRoot
public class MainView extends VerticalLayout implements View {
// Menu navigation button listener
VerticalLayout menuContent;
Panel equalPanel;
Button logout;
public MainView(Navigator navigator) {
Design.read(this);
logout.addClickListener(event ->
navigator.navigateTo(""));
}
@DesignRoot
class AnimalViewer extends VerticalLayout {
Label watching;
Embedded pic;
Label back;
public AnimalViewer(String animal) {
Design.read(this);
watching.setValue("You are currently watching a " +
animal);
pic.setSource(new ThemeResource(
"img/" + animal + "-128px.png"));
back.setValue("and " + animal +
" is watching you back");
}
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
if (event.getParameters() == null
|| event.getParameters().isEmpty()) {
equalPanel.setContent(
new Label("Nothing to see here, " +
"just pass along."));
return;
} else
equalPanel.setContent(new AnimalViewer(
event.getParameters()));
}
}
答案 0 :(得分:2)
正确的位置很可能是/src/main/resources/com/andrei/MainView.html
。