views:

371

answers:

3

I have 2 comboBoxes 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.

+2  A: 

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.

aalmiray
Got it. Thanks!!
kulkarni
from what I read the items property isn't being bound as a source. The source will only fire an update if the whole collection is updated, i.e. model.states = ['TT', 'CX']if you want to trigger on modifications of the list, use an observable list and bind to the events of the observable list.
shemnon
A: 

Do you mind posting the code for getting this to work? I'm having the same issues and I wanted to see what you did to make sure that I'm not missing something.

Thanks!

wlindner
+1  A: 
    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))
kulkarni