2014-12-07 109 views
1

我將如何在Vaadin UI中的子視圖之間導航。我希望網站上的標題保持靜態,就像母版頁和要使用導航更改的內容視圖。我怎麼能在Vaadin做到這一點。VAADIN 7:導航子視圖

回答

2

那麼你可以簡單地設計你的用戶界面頭部(和其他東西,如果需要的話)和一個組件,將充當變化的內容的佔位符。 然後我添加一個方法,接收新內容以顯示並放入佔位符。 下面是一些代碼:

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); 
    } 

} 
+0

changeContent函數中的主要內容是什麼? – carora3 2014-12-07 21:16:07

+0

「主」應該是「內容」,對不起(編輯代碼)。 – shoguren 2014-12-07 21:46:42

+0

但問題是我無法使用瀏覽器後退按鈕導航回到上一頁。 – carora3 2015-01-13 10:53:01

0

如果您的應用程序需要支持瀏覽器的書籤和導航(後退和前進按鈕),你需要使用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

描述implemente查看界面,如果你使用Spring,你可以還可以使用插件,如SpringVaadinIntegrationvaadin4spring以使其更容易,並且每個插件都具有其他幾個優點。