JavaFX Form Validation
Tom Eugelink
tbee at tbee.org
Mon Jun 11 04:27:04 PDT 2012
+1 on the style. I was thinking in the line of this:
new TextField().validators(new MandatoryValidator(), new UserNameValidator());
Tom
On 2012-06-11 13:08, Randahl Fink Isaksen wrote:
>
>
> Finally, from what I have seen of the JGoodies approach, it looks very procedural, and very programming intensive. I found this example online:
>
> |public ValidationResult validate() {
> ValidationResult result = new ValidationResult();
> if (ValidationUtils.isEmpty(mUser.getUserName())) {
> result.addError("User name is required");
> }
> if (ValidationUtils.isEmpty(mUser.getPassword())) {
> result.addError("Password is required");
> }
> return result;
> }|
>
>
> Even though the validation logic to check for emptiness is reusable, the developer still has to write a lot of if-then logic. I would much rather want JavaFX to have an object oriented approach, allowing me to write something like
>
> TextField userNameTextField = new TextField(new UserNameValidator());
>
> where the UserNameValidator class does all of the JGoodies stuff above for me and can easily be reused among different parts of my application. With this approach it is obvious that people will start sharing EmailAddressValidator, ConfigurablePasswordValidator, LicensePlateValidator, etc.
More information about the openjfx-dev
mailing list