« Return to Thread: SwingBuilder/Griffon how to bind items/model to combobox?

SwingBuilder/Griffon how to bind items/model to combobox?

by bubbles.way :: Rate this Message:

Reply to Author | View in Thread

I have view in Griffon with combobox which bind items (=combobox model) to one attribute of griffon model:

AppView.groovy:

comboBox(items: model.toItems)

AppModel.groovy:

class AppModel {
  ...
 @Bindable List toItems
}



I would like to have behavior to change combobox items  whenever I modify toItems attribute (e.g. in controller - action that handles button click to change available items in combobox).

I have tried to create and bind toItems to combobox in following way (according to some examples):

comboBox(items: bind(source: model, sourceProprety: 'toItems', value: model.toItems))

but this does not work! Application does not start. There is an exception:
java.lang.RuntimeException: Failed to create component for 'comboBox' reason: java.lang.RuntimeException: The value argument of 'comboBox' must be of type javax.swing.JComboBox

The  solution I have found is to define helper attribute 'toCombo' in controller(!) and assign created combobox to it.

AppController.groovy:
def toCombo

AppView.groovy:
 controller.toCombo = comboBox(items: model.toItems)

Then, in controller, whenever I change model.toItems, I have to change combobox model(= items) as well.

AppController.groovy:
model.toItems = ['A', 'B', 'C']
toCombo.model = new DefaultComboBoxModel(model.toItems as Object[])


Is there any way to make combobox items(=model) directly bind-able and not to do such workaround?

Thanks for any response,

bubbles.way

 « Return to Thread: SwingBuilder/Griffon how to bind items/model to combobox?