开发者

populate a comboBox in Griffon App dynamically

I have 2 comb开发者_C百科oBoxes in my View of Griffon App (or groovy swingBuilder)

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))

The getStates() in the controller, populates @Bindable List states = [] in the model based on the country selected.

The above code doesn't give any errors, but the states are never populated.

I changed the states from being List to a range object(dummy), it gives me an error MissingPropertyException No such property items for class java.swing.JComboBox.

Am I missing something here? There are a couple of entries related to this on Nabble but nothing is clear. The above code works if I had a label instead of a second comboBox.


I believe that the items: property is not observable and it's only used while the node is being built. You may have better results by setting the binding on the model or by using GlazedLists' EventList.


Model:

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

Controller:

    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})}
    }

View:

    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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜