Skip to content

Instantly share code, notes, and snippets.

@prule
Last active December 14, 2015 08:58
Show Gist options
  • Save prule/5061107 to your computer and use it in GitHub Desktop.
Save prule/5061107 to your computer and use it in GitHub Desktop.
Griffon/JavaFX - Adding a change listener to a text field Part 2
import javafx.beans.value.ChangeListener
import javafx.beans.value.ObservableValue
import org.apache.commons.lang.StringUtils
// model
@FXBindable String amount1
// view
textField(id: 'amount1', text: bind(model.amount1Property))
noparent {
amount1.textProperty().addListener({ ObservableValue<? extends String> observable, String oldValue, String newValue ->
try {
if (StringUtils.isNotBlank(newValue)) {
Integer.parseInt(newValue);
}
} catch (Exception e) {
observable.setValue(oldValue);
}
} as ChangeListener<String>)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment