JavaFX - field validation

I am new to javaFX. I created one registration form using fxml. Now I want to implement field validation functionality. I am trying to do a check for TextField, but still I am not getting it. Please help me.

thanks naresh

+6
source share
4 answers

Unfortunately, there is no validation framework in JavaFX. Even frameworks like Granite Data Services had problems with bean validation with JavaFX: http://granitedataservices.com/blog/2012/11/29/thoughts-about-javafx-and-bean-validation/

If you are interested in validating a bean with JavaFX, Granite will generate java beans with JavaFX property fields with bean checking enabled (you test your java bean that is bound to your javafx components). This may be a good solution or a good source of inspiration for your problem.

+2
source

As @zenbeni noted, automatic validation fails, but you can implement your own event handlers. How you want to implement it, it will be determined which event handler you choose to implement. They can be very wild in complexity. Here is someone else trying to create a fully validate Text Field component: JavaFX 2.2 FXML Validated TextField

You can get rid of a simpler implementation using the setOnAction handler described here http://docs.oracle.com/javafx/2/api/javafx/scene/control/TextField.html#setOnAction(javafx.event.EventHandler) , but if you are going to do it many times, you need something more complete, like the implementation above.

0
source

My suggestion is to use JideFX to check fields and other special controls such as Calendar and pop-ups.

Please check www.jidesoft.com

0
source

You can check for lost focus on the control. This is a fairly common cross-platform method ...

textField.focusedProperty().addListener((observable, oldValue, newValue) -> { if(textField.isFocused() == false) { LOGGER.debug("Validate on lost focus here..."); } }); 

JavaFX 8

0
source

Source: https://habr.com/ru/post/953904/


All Articles