Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3470

In SwingBuidler bind() validator: attribute doesn't pass value as closure arg

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6, 1.6.1, 1.7-beta-1
    • 1.6.2, 1.7-beta-1
    • Swing
    • None

    Description

      This should work, but doesn't

              SwingBuilder swing = new SwingBuilder()
              def model = new BindableBean()
      
              def isInteger = { v ->
                try {
                    Float.parseFloat(v)
                    return true
                } catch (NumberFormatException ignore) {
                    return false
                }
              }
      
              swing.actions {
                frame( title: "Binding test", size: [100,60]) {
                  textField( id: "t1", text: bind(target:model, value:'123',
                    targetProperty: "value", validator: isInteger, converter: Integer.&parseInt) )
                }
              }
              assert model.value == 123
              swing.t1.text = '1234'
              assert model.value == 1234
              swing.t1.text = 'Bogus'
              assert model.value == 1234
              swing.t1.text = '12345'
              assert model.value == 12345

      The issue is that the validator is called without the source value, making the validator blind to values and quite useless

      Attachments

        Activity

          People

            shemnon Daniel Ferrin
            shemnon Daniel Ferrin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: