2013-05-28 2 views
0

ComboBox의 모든 항목을 제거하고 다른 버튼을 클릭 할 때 다른 항목으로 채우고 싶습니다. removeAll()을 사용하지만 이전에 선택한 값이 여전히 콤보에 있습니다. 이것이 내가 한 일이다.ComboBox에서 선택한 값을 제거하는 방법

@AutoGenerated 
private AbsoluteLayout mainLayout; 
@AutoGenerated 
private GridLayout gridLayout_1; 
@AutoGenerated 
private HorizontalLayout horizontalLayout_1; 
@AutoGenerated 
private Button cancelBtn; 
@AutoGenerated 
private Button saveBtn; 
@AutoGenerated 
private TextField openingHoursTf; 
@AutoGenerated 
private Label label_10; 
@AutoGenerated 
private TextField emailTf; 
@AutoGenerated 
private Label label_9; 
@AutoGenerated 
private TextField phoneTf; 
@AutoGenerated 
private Label label_3; 
@AutoGenerated 
private TextField postCodeTf; 
@AutoGenerated 
private Label label_4; 
@AutoGenerated 
private TextArea addressLine2Tf; 
@AutoGenerated 
private Label label_8; 
@AutoGenerated 
private TextArea addressLine1Tf; 
@AutoGenerated 
private Label label_2; 
@AutoGenerated 
private TextArea descriptionTf; 
@AutoGenerated 
private Label label_5; 
@AutoGenerated 
private TextField nameTf; 
@AutoGenerated 
private Label label_1; 
@AutoGenerated 
private ComboBox statusComboBox; 
@AutoGenerated 
private Label label_21; 
@AutoGenerated 
private ComboBox typeComboBox; 
@AutoGenerated 
private Label label_19; 
@AutoGenerated 
private TextField codeTextField; 
@AutoGenerated 
private Label label_17; 
@AutoGenerated 
private ComboBox areaComboBox; 
@AutoGenerated 
private Label label_15; 
@AutoGenerated 
private ComboBox stateComboBox; 
@AutoGenerated 
private Label label_13; 
@AutoGenerated 
private ComboBox countryComboBox; 
@AutoGenerated 
private Label label_11; 
@AutoGenerated 
private Upload image_upload_1; 
@AutoGenerated 
private Label label_6; 
/** 
* The constructor should first build the main layout, set the composition 
* root and then do any custom initialization. 
* 
* The constructor will not be automatically regenerated by the visual 
* editor. 
*/ 

private Window window; 
private StoreDTO store; 
private StoreDataProvider storeDataProvider; 
private StoreContainer storeContainer; 
List<CountryDTO> countries = null; 
List<StoreTypeDTO> storeTypeList = null; 
List<AreaDTO> areasList=null; 
String imageMediumUrl; 
String imageHighUrl; 
String imageLowUrl; 
private ImageUploader uploader; 

public NewStoreWindow() { 
    buildMainLayout(); 
    setCompositionRoot(mainLayout); 
    statusComboBox.addItem(Status.ACTIVE); 
    statusComboBox.addItem(Status.INACTIVE); 
    statusComboBox.setNullSelectionAllowed(false); 

    try { 
     countries = StoreDataProvider.getStoreDataProvider() 
       .getAllCountries(); 
    } catch (Exception e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
    } 

    for (CountryDTO country : countries) { 
     countryComboBox.addItem(country); 


    } 
    if (countries != null && !countries.isEmpty()) { 
     countryComboBox.select(countries.get(0)); 
    } 
    countryComboBox.setNullSelectionAllowed(false); 
    CountryDTO dto=(CountryDTO)countryComboBox.getValue(); 

    try { 
     areasList=StoreDataProvider.getStoreDataProvider().getAreasByCountry(dto.getId()); 
     areaComboBox.removeAllItems(); 
     for (AreaDTO area : areasList) { 
      areaComboBox.addItem(area); 

     } 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    areaComboBox.setNullSelectionAllowed(false); 
    countryComboBox.addListener(new ValueChangeListener() { 

     @Override 
     public void valueChange(ValueChangeEvent event) { 
      areaComboBox.removeAllItems(); 
      areaComboBox.setValue(null); 
      CountryDTO dto=(CountryDTO)countryComboBox.getValue(); 

      try { 
       areasList=StoreDataProvider.getStoreDataProvider().getAreasByCountry(dto.getId()); 

       for (AreaDTO area : areasList) { 
        areaComboBox.addItem(area); 

       } 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 


     } 

    }); 
+0

더 많은 코드를 제공 할 수 있습니까? 처음에는 'countryComboBox'와 'areaComboBox'가 어디에 생성되었는지 불분명하기 때문에보기가 어려워 보입니다. – RishikeshDhokare

+0

웹 응용 프로그램에 있습니까? 아니면 무엇입니까? – MaheshVarma

+0

@MaheshVarma 예 웹 앱에 있음 –

답변

1

당신이 사용하는 것보다 즉시 적용 국가 - 콤보 상자의 변경을 원한다면 :

countryComboBox = new ComboBox(); 
countryComboBox.setImmediate(true); 

ValueChangeListener 내 코드가 즉시 실행됩니다 이런 식으로. 그러면 지역 목록이 지워집니다. 과도한 트래픽을 유발할 수 있으므로 모든 것을 "즉시"로 설정하지 마십시오.

+0

@Sanjaya Oh 그리고 다음에 코드의 실행 가능한 예제를주세요. 테스트하기 위해 붙여 넣기 도구를 복사 할 수있을 때 질문에 대답하는 것이 더 쉽고 빠릅니다. – DKM

+0

고마워.이게 도움이 됐어. –

1

setNullSelectionAllowed(false)처럼 combox 상자에는 항상 값이 있어야합니다. 목록 및 콤보 상자를 다시 채우려면 값을 목록의 첫 번째 dto로 설정하십시오.

areaComboBox.removeAllItems(); 
CountryDTO dto = (CountryDTO)countryComboBox.getValue(); 

areasList = StoreDataProvider.getStoreDataProvider().getAreasByCountry(dto.getId()); 

for (AreaDTO area : areasList) { 
    areaComboBox.addItem(area); 
} 

// Set value to the first of the list  
if(!areaList.isEmpty()){ 
    areaComboBox.setValue(areasList.get(0)); 
} 
관련 문제