Skip to content

Instantly share code, notes, and snippets.

@ivanarrizabalaga
Created March 27, 2014 15:42
Show Gist options
  • Save ivanarrizabalaga/9810480 to your computer and use it in GitHub Desktop.
Save ivanarrizabalaga/9810480 to your computer and use it in GitHub Desktop.
Griffon, a mutual binding with validation (not working)
import groovy.beans.Bindable
import groovy.swing.SwingBuilder
class MyModel {
@Bindable String value
}
def model = new MyModel()
def isNumber = { val ->
if(!val) return true
try {
println "->isNumber($val): model.value: ${model.value}"
Double.parseDouble(val)
} catch(NumberFormatException e) {
false
}
}
def swing = new SwingBuilder()
swing.edt {
frame(title: 'Binding', pack: true, visible: true) {
gridLayout(cols: 2, rows: 3)
label 'Validator'
//OPT1 should work but it doesnt
textField(columns: 20, text: bind('value', source: model, mutual:true,validator: isNumber))
//OPT2 validator: ok, mutual: ko (cannot initialize model.value)
//textField(columns: 20, text: bind('value', target: model, mutual:true,validator: isNumber))
label 'Only numbers here'
textField(columns: 20, text: bind('value', source: model))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment