Vaadin Navigator NPE

时间:2016-03-06 15:10:26

标签: java web navigation vaadin

我无法让Vaadin Navigator开始工作。出于某种原因,我总是得到NPE。也许你们可以帮助我。我要提到我刚刚开始使用Vaadin。

所以这是代码

@Theme("mytheme")
@Widgetset("de.javahouse.jobwiz.MyAppWidgetset") 
public class BasicInformation extends UI {

public static final String VIEW_NAME_BASIC = "basic";
public static final String VIEW_NAME_ADV = "advanced";

private Navigator nav;
private static final long serialVersionUID = 2548993131483469880L;

@Override
protected void init(VaadinRequest vaadinRequest) {

    HorizontalLayout layout = generateContent();
    nav = new Navigator(this,this);
    nav.addView(VIEW_NAME_ADV, new AdditionalInformation());

//这不行 //nav.addView(VIEW_NAME_BASIC,(Class)BasicInformation.class);

    setContent(layout);


}

private HorizontalLayout generateContent(){

    HorizontalLayout layout = new HorizontalLayout();

    FormLayout form = new FormLayout();

    OptionGroup single = new OptionGroup("Gender");
    single.addItems("Male", "Female");
    form.addComponent(single);

    TextField tfFirstname = new TextField("First Name");
    tfFirstname.setRequired(true);
    form.addComponent(tfFirstname);

    TextField tfFamilyName = new TextField("Family Name");
    tfFamilyName.setRequired(true);
    form.addComponent(tfFamilyName);

    TextField tfEmail = new TextField("E-mail");
    tfEmail.setRequired(true);
    form.addComponent(tfEmail);

    Button btSave = new Button("Save and Proceed");
    btSave.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            nav.navigateTo(VIEW_NAME_ADV);
        }
    });
    form.addComponent(btSave);

    layout.addComponent(form);



    return layout;
}

@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = BasicInformation.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
}

}

public class AdditionalInformation extends VerticalLayout implements View {

private static final long serialVersionUID = 1578488973205488083L;

public AdditionalInformation(){
    Label lbl = new Label("Whatever");
    addComponent(lbl);

}

@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
    // TODO Auto-generated method stub

}

}

这是我收到的错误消息。我不知道自己做错了什么。感觉就像我检查了所有在线教程并复制它真的像他们一样。

BTW:我正在使用jetty来运行该站点(仅用于测试)

javax.servlet.ServletException: com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: Trying to navigate to an unknown state '' and an error view provider not present
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:366)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1667)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:172)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:497)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:610)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:539)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: Trying to navigate to an unknown state '' and an error view provider not present
    at com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1464)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1421)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:364)
    ... 24 more
Caused by: java.lang.IllegalArgumentException: Trying to navigate to an unknown state '' and an error view provider not present
    at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:575)
    at com.vaadin.ui.UI.doInit(UI.java:687)
    at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:214)
    at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1409)
    ... 25 more

提前多多感谢

1 个答案:

答案 0 :(得分:2)

有一个thread in vaadin forum about this issue

我面对这个问题,修复方法是模拟一个空的引用视图。 在你的情况下,我建议你设置

public static final String VIEW_NAME_ADV = ""; // force to empty string

否则,相同的vaadin线程表明修复错误视图实例可以是修复

this.navigator.setErrorView(myView);