2014-09-04 113 views
0

我手風琴有點問題。例如,當我嘗試刪除手風琴的一個選項卡時,我找不到任何方法來執行此操作。任何人都知道我可以做到這一點?如何動態刷新Vaadin手風琴?

這裏有一些我的代碼。

public ResponseUI(final Window mainWindow, boolean allowSave, final Context c) { 
    InjectHelper.inject(this); 
    buildMainLayout(); 
    setCompositionRoot(mainLayout); 

    // TODO add user code here 
    //TODO: add responses to accordion 

    List<Templates> templatesReenvia = templateBusinessManager.getAllTemplatesResposta();   
    boolean bandera = true; 
    for(Templates tmpl : templatesReenvia) { 
     accordion_respostes.addTab(new PlantillaView(mainWindow, panel_1, c, tmpl), tmpl.getSubject()); 
    } 
    panel_1.addComponent(new ResponseForm(mainWindow,allowSave)); 

    panel_respostes.setScrollable(true);  
    button_1.addListener(new Button.ClickListener() { 
     public void buttonClick(ClickEvent event) {  
      final Window dialog = new Window("Edició de plantilla"); 
      dialog.setModal(true); 
      mainWindow.addWindow(dialog); 
      dialog.addComponent(new PlantillaForm(mainWindow, c, false)); 
      dialog.setWidth("85%"); 
     } 
    }); 
} 

templateBusinessManager0我有CRUD方法,所以我只需要知道如何在這種方法中的一個發生刷新我的手風琴。希望有人有更好的解決方案。

回答

0

您可以用removeComponent刪除或替換爲replaceComponent,就像在任何其他組件容器中一樣。如果您的組件無法自行更改其狀態,則必須將它們交換出去。

+0

我需要刷新不刪除:/ – GooDFighTy 2014-09-04 15:10:28

+0

刪除+添加=刷新,因爲它不是相同的對象 – 2014-09-04 16:58:24

+0

@GooDFighTy還有replaceComponent。你的第一句話提到「刪除」,所以我認爲,這是你唯一的問題 – cfrick 2014-09-04 17:25:22

0

此示例應用程序在單擊按鈕時將一個選項卡的內容替換爲其他內容。另請注意,Accordion/TabSheet不會自動替換選項卡的元數據(例如標題),而是從舊選項卡的元數據中複製。在這個例子中,即使內容本身被交換,標題也總是說「標籤1」。

public class AccordionUI extends UI { 

private Accordion accordion; 
private Panel tab1, tab2, tab3; 

@Override 
protected void init(VaadinRequest request) { 

    HorizontalLayout hl = new HorizontalLayout(); 
    setContent(hl); 

    tab1 = new Panel("Tab 1"); 
    tab2 = new Panel("Tab 2"); 
    tab3 = new Panel("Tab 3"); 

    accordion = new Accordion(tab1, tab2); 
    hl.addComponent(accordion); 

    Button button = new Button("Replace"); 
    button.addClickListener(new ClickListener() { 

     @Override 
     public void buttonClick(ClickEvent event) { 
      accordion.replaceComponent(tab1, tab3); 
     } 
    }); 
    hl.addComponent(button); 
} 

}

0

Vaadin狀態(見https://vaadin.com/book/vaadin7/-/page/layout.accordion.html):您可以使用相同手風琴的標籤頁。

如果你看看標籤頁的文檔,你會發現這樣的事情:

tabsheet.removeTab(tab); 

這:

tabsheet.addTab(myTab).setCaption("My Tab"); 

所以你可以刷新標題,關閉該標籤或只是使用replaceComponent()方法更改組件內部。

+0

手風琴也mehod'addTab(組件,標題)':) – xxxvodnikxxx 2015-08-06 06:58:01

0

如果需要刪除特定的標籤,你可以使用removeTab(Tab tabComponent) - 標籤PARAM你能由getTab(component)得到(組件是一個,你使用它,而調用addTab(Component newTabComponent)方法:O) (或直接的方式replaceComponent(oldComponent, newComponent)應作品也)

如果您需要刪除所有協議選項卡,我使用accordionInstance.removeAllComponents(),但如果removeTabreplaceComponent很爛,這裏還有way-你可以用一些特定的佈局添加標籤和你打電話removeComponents()addComponent(newComponent)上佈局:)