2010-02-21 152 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