2016-03-28 136 views
0

我做導航的vaadin 7應用程序中使用,其中我試圖從UI導航到視圖導航,但得到以下錯誤Navigator在Vaadin 7

java.lang.IllegalArgumentException: Trying to navigate to an unknown state '' and an error view provider not present error. 

UI類:

public class NavigationUI extends UI { 

@WebServlet(value = "/*", asyncSupported = true) 
@VaadinServletConfiguration(productionMode = false, ui = NavigationUI.class) 
public static class Servlet extends VaadinServlet { 
} 

final private String navigatorView = "NEXT"; 
private Navigator navigator = null; 


@Override 
protected void init(VaadinRequest request) { 
    HorizontalLayout hori = new HorizontalLayout(); 
    final VerticalLayout layout = new VerticalLayout(); 
    hori.setMargin(true); 
    layout.setMargin(true); 
    setContent(hori); 
    hori.addComponent(layout); 
    Panel pnl = new Panel(); 
    hori.addComponent(pnl); 
    navigator = new Navigator(this,pnl); 
    navigator.addView("abc", Welcome.class); 
    Button button = new Button("Click Me"); 
    layout.addComponent(button); 
    button.addClickListener(new Button.ClickListener() { 
     public void buttonClick(ClickEvent event) { 
      navigator.navigateTo("abc"); 
     } 
    }); 
} 
} 

視圖類:

public class Welcome extends VerticalLayout implements View { 


public Welcome() { 
    // TODO Auto-generated constructor stub 
    VerticalLayout layout = new VerticalLayout(); 
    Button back = new Button("Go Back"); 
    layout.addComponent(back); 
    addComponent(layout); 
} 

@Override 
public void enter(ViewChangeEvent event) { 
    // TODO Auto-generated method stub 
    Notification.show("Welcome Here!!!"); 
} 
} 

找出我在做什麼錯在此,我要感謝:)

回答

1

如異常情況所述,您沒有與''匹配的視圖;

你必須添加類似;

navigator.addView("", Welcome.class); 

或寫入網址爲

http://localhost:8080/context_root/#!abc