Created
March 27, 2014 15:42
-
-
Save ivanarrizabalaga/9810480 to your computer and use it in GitHub Desktop.
Griffon, a mutual binding with validation (not working)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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