|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
SwingBuilder/Griffon how to bind items/model to combobox?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 |
|
|
Re: SwingBuilder/Griffon how to bind items/model to combobox?Another solution is to make ComboBoxModel part of the griffon model and use it for source binding:
AppModel.groovy: class AppModel { ... @Bindable ComboBoxModel toModel } Bind it in view: AppView.groovy comboBox( 'model': bind {model.toModel}) Then, in controller you can change combobox model like this: AppController.groovy: model.toModel = new DefaultComboBoxModel(['A', 'B', 'C'] as Object[]) This does not require to have access to combobox object in controller. Unfortunately your model class has to be aware of Swing ComboBoxModel class, which is not so clean solution. Another problem I have found is when trying to bind selected item. It looks like you can bind it as source (change model -> change selection in combobox) or as target (change selection in combobox -> change model), but not as both. AppView.groovy: selectedItem: bind(target: model, targetProperty: 'to', value: model.to)) or selectedItem: bind(source: model, sourceProperty: 'to', value: model.to)) but in case you use: selectedItem: bind(source: model, sourceProperty: 'to', target: model, targetProperty: 'to', value: model.to)) only source is working. As a workaround you have to remember combobox (again!) and perform update of selected item in controller. AppController.groovy: model.to = 'A' toCombo.selectedItem = model.to // workaround |
|
|
Re: SwingBuilder/Griffon how to bind items/model to combobox?This sounds like a bug in the comboBoxFactory when bindings are defined, please file a JIRA ticket so that we don't forget, thank you!
Cheers, Andres
|
|
|
Re: SwingBuilder/Griffon how to bind items/model to combobox?Report created:
http://jira.codehaus.org/browse/GRIFFON-67
|
| Free embeddable forum powered by Nabble | Forum Help |