2010-02-21 154 views
1

我在我的格里芬應用(或常規swingBuilder)的視圖2個組合框填充組合框動態

country = comboBox(items:country(), selectedItem: bind(target:model, 'country', 
      value:model.country), actionPerformed: controller.getStates) 

state = comboBox(items:bind(source:model, sourceProperty:'states'), 
        selectedItem: bind(target:model, 'state', value:model.state)) 

控制器中的getStates(),填充@Bindable列表指出= []中基於所選國家的模型。

上述代碼不會給出任何錯誤,但狀態永遠不會填充。

我將List從List更改爲範圍對象(dummy),它給了我一個錯誤MissingPropertyException類java.swing.JComboBox沒有這樣的屬性項。

我在這裏錯過了什麼嗎?在Nabble上有一些與此相關的條目,但沒有任何說明。上面的代碼工作,如果我有一個標籤,而不是第二個組合框。

回答

2

我相信items:屬性是不可觀察的,它只在節點被構建時才使用。您可以通過在模型上設置綁定或使用GlazedLists的EventList獲得更好的結果。

+0

明白了。謝謝!! – kulkarni 2010-02-22 06:04:41

+0

從我讀的項目屬性不被綁定爲源。如果整個集合被更新,則源只會觸發更新,即 model.states = ['TT','CX'] 如果要觸發列表修改,使用可觀察列表並綁定到可觀察列表的事件。 – shemnon 2010-02-25 00:44:40

2

型號:

@Bindable String country = "" 
    EventList statesList = new BasicEventList() 

控制器:

def showStates = { evt = null -> 
    model.statesList.clear() 
    def states = [] 
    if(model.country == "US") 
       states = ["CA","TX", "CO", "VA"] 
    else if(model.country == "Canada") 
     states = ["BC", "AL"] 
    else 
      states = ["None"] 

    edt {model.statesList.addAll(states.collect{it})} 
    } 

查看:

def createComboBoxStatesModel() { 
        new EventComboBoxModel(model.daysList) } 

    comboBox(items:["USA","Canada","other"], selectedItem: bind(target:model, 'country', value: model.country), actionPerformed : controller.showStates) 

    comboBox(model: createComboBoxStatesModel(), selectedItem: bind(target:model, 'state', value:model.state)) 
+0

我想'createComboBoxStatesModel'封閉中的'model.daysList'應該是'model.statesLlist'? – 2011-10-19 19:05:59