I created one registration form using fxml. Now I want to implement the field validation functionality. I am trying to implement the validation for TextField but still I am not getting it.
Unfortunately, there is no validation framework within JavaFX. Even frameworks such as Granite Data Services had troubles with bean validation with JavaFX: http://granitedataservices.com/blog/2012/11/29/thoughts-about-javafx-and-bean-validation/ (!Wayback)
If you are interested with bean validation with JavaFX, Granite generate java beans with JavaFX Property fields with bean validation enabled (you validate your java bean which is binded to your javafx components). It can be a good solution, or a good inspiration for your problem.
You can validate on lost focus on the control. That is a pretty common cross-platform method...
textField.focusedProperty().addListener((observable, oldValue, newValue) ->
{
if(textField.isFocused() == false)
{
LOGGER.debug("Validate on lost focus here...");
}
});
JavaFX 8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With