动态填充 Griffon 应用程序中的组合框

发布于 2024-08-22 17:57:58 字数 689 浏览 8 评论 0原文

我的 Griffon App(或 groovy swingBuilder)视图中有 2 个组合框。

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

控制器中的 getStates(),根据所选国家/地区在模型中填充 @Bindable List states = []。

上面的代码没有给出任何错误,但状态从未被填充。

我将状态从 List 更改为范围对象(虚拟),它给我一个错误 MissingPropertyException No such property items for class java.swing.JComboBox。

我在这里错过了什么吗? Nabble 上有几个与此相关的条目,但没有任何内容是明确的。如果我有一个标签而不是第二个组合框,上面的代码就可以工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光沙漏 2024-08-29 17:57:58

我相信 items: 属性是不可观察的,它仅在构建节点时使用。通过在模型上设置绑定或使用 GlazedLists 的 EventList 可能会获得更好的结果。

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.

骄兵必败 2024-08-29 17:57:58

型号:

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

控制器:

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

视图:

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

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文