0

I'm trying to update the content of a combo box (using Griffon 1.2.0, with the JavaFX plugin).

My model:

class MyModel {
    List monthList = FXCollections.observableList([new DateMidnight()])

    def convertDate = [
            fromString: { String s ->
                return new DateMidnight(DateTimeFormat.forPattern("yyyy-MM").parseDateTime(s))
            },
            toString: { DateMidnight d ->
                return "2011-10"
            }
    ] as StringConverter
}

My view contains:

comboBox(items: (model.monthList), converter: model.convertDate)

Now I have a controller action which gets invoked when they push a button:

def load = {
        execInsideUIAsync {
            def months = myService.buildMonthList()
            model.monthList.addAll(months)
        }
} 

The problem is that the combo box content never changes. Can anyone help me understand what I'm missing?

There's no documentation on ComboBox yet http://groovyfx.org/docs/guide/single.html#choiceBoxComboBox

Also, have I implemented the converter correctly?

prule
  • 2,536
  • 31
  • 32

1 Answers1

0

The problem is that GroovyFX.comboBox creates a new List instead of using the one you pass as argument for items: This problem occurs with tableView as well. A temporary workaround would be to set the items property directly, like this

 comboBox(id: 'combo')
 noparent { combo.items = model.monthList }
Andres Almiray
  • 3,236
  • 18
  • 28
  • Unfortunately this hasn't worked for me. I've defined my combobox: comboBox(id: 'months', converter: model.convertDate) and then used the noparent block: noparent { months.items = model.monthList and then in my controller I update the model model.monthList.clear() model.monthList.addAll(months) but the view never changes. The only way I've ever been able to manipulate the combobox is to directly access view.months.items and clear/populate it directly. Not ideal. – prule Feb 23 '13 at 22:06
  • Hmm could it be a threading issue? I ran the code with Griffon 1.2.0 and groovyfx/javafx 0.8. See https://gist.github.com/aalmiray/5023272 for details. The Guide describes @Threading in detail too http://griffon.codehaus.org/guide/latest/guide/threading.html#annotationBasedThreading – Andres Almiray Feb 24 '13 at 09:56
  • Heh, I created a new app to try your example, and it works fine. But I still can't get it working in my existing app. When I have time I'll try to get it working properly. Thanks for your help. – prule Feb 25 '13 at 01:12