2012-10-05 69 views
0

我有4個選項卡。我想阻止用戶獲取(使用window.alert示例)到另一個選項卡,因爲它尚未填充當前選項卡。用戶完成填寫所有字段後,會在當前選項卡內出現一個文本(表示他可以移動到下一個選項卡)。他將能夠點擊下面的標籤。允許/禁止GWT中TabPanel的選項卡選擇

我應該使用BeforeSelectionEvent處理程序還是SelectionHandler?

回答

0

對於GWT的TabPanel:

@Override 
public boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex) 
{ 
    String currentTabName = widget.getTabHTML(widget.getSelectedTab()); // for reference 
    String tabNameYouTryingToSelect = widget.getTabHTML(tabIndex); // for reference 

    // check some external self-written method and return true or false to allow/disallow selection 
    if (isCurrentlyActiveTabBuilt()){ 
     return true; 
    } else { 
     Window.alert("You must fill all fields before proceeding to the next step."); 
     return false; 
    } 
} 
+0

isCurrentlyActiveTabBuilt()是函數或變量? – user978504

+0

這必須是您定義完整性條件的自定義方法。 Smth,如: return field1.isChecked()&& field2.isChecked && field3.value!= null ...等 – alexp

1

我做這個代碼來響應我的問題,但太長

is there a possibility to turn it into a short function ? 
this.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() { 
       public void onBeforeSelection(BeforeSelectionEvent<Integer> event) { 
       if (Application.get().getChampsObligatoire().values().contains("Fiche")) { 
        if (event.getItem().intValue() > 0){ 
        event.cancel(); 
        Window.alert("You must fill all fields before proceeding to the next step."); 
        } 

        } 
       if (Application.get().getChampsObligatoire().values().contains("projet")) { 
        if (event.getItem().intValue() > 1){ 
        event.cancel(); 
        Window.alert("You must fill all fields before proceeding to the next step."); 
        } 
       } 
        if (Application.get().getChampsObligatoire().values().contains("cibles")) { 
         if (event.getItem().intValue() > 2){ 
         event.cancel(); 
         Window.alert("You must fill all fields before proceeding to the next step."); 
         } 

         } 

        if (Application.get().getChampsObligatoire().values().contains("Ressources")) { 
         if (event.getItem().intValue() > 3){ 
         event.cancel(); 
         Window.alert("You must fill all fields before proceeding to the next step."); 
         } 

         } 
        if (Application.get().getChampsObligatoire().values().contains("Contrôle")) { 
         if (event.getItem().intValue() > 4){ 
         event.cancel(); 
         Window.alert("You must fill all fields before proceeding to the next step."); 
         } 

         } 



       } 

      }); 
相關問題