------- PresentationModel.groovy ------------------ import groovy.beans.Bindable public class PresentationModel{ @Bindable String name @Bindable String firstName @Bindable Date birthday } ---------- FormsTester.groovy --------------- import java.text.SimpleDateFormat import javax.swing.* import java.awt.Color import groovy.swing.SwingBuilder public class FormsTester { public static void main(args) { def dateConverter = { dateString -> println "date converter: input=${dateString}" new SimpleDateFormat("dd.MM.yyyy").parse(dateString) } def dateValidator = { dateString -> println "date validator: input=${dateString}" try { def parser = new SimpleDateFormat("dd.MM.yyyy") parser.lenient = false parser.parse(dateString) } catch (Exception e) { return false } return true } def model = new PresentationModel() def swing = new SwingBuilder() def frame = swing.frame(title: 'Forms Test', defaultCloseOperation: JFrame.DISPOSE_ON_CLOSE, size: [800, 600], show: false, locationRelativeTo: null) { panel { tableLayout(cellpadding:10) { tr { td { label('Name:', id:'nameLabel') } td { textField(id:'nameText', columns:40, text: bind(target:model, targetProperty:'name')) } } tr { td { label('First name:', id:'firstNameLabel') } td { textField(id:'firstNameText', columns:40, text: bind(target:model, targetProperty:'firstName')) } } tr { td { label('born on:', id:'birthdayLabel') } td { /********* this code runs fine ***** def tf def binding = bind ( validator: { dateValidator(tf?.text) }, converter: dateConverter, target:model, targetProperty:'birthday' ) tf = textField('01.01.1970', id:'birthdayText', columns:20, text: binding) ***********/ // this code crashes with an exception def tf = textField('01.01.1970', id:'birthdayText', columns:20) def binding = bind ( source: tf, sourceProperty: 'text', validator: { dateValidator(tf?.text) }, converter: dateConverter, target:model, targetProperty:'birthday' ) } } tr { td { label('reformatted:', id:'formattedBirthdayLabel') } td { def binding = bind ( converter: { it as String }, source:model, sourceProperty:'birthday' ) label(id:'formattedBirthdayText', text: binding) } } } } } frame.show() } }