JavaFX Form Validation
Randahl Fink Isaksen
randahl at rockit.dk
Mon Jun 11 04:30:01 PDT 2012
I like your idea Tom. But if it should look like the existing JavaFX
API's, it will probably be more like
myTextField.getValidators().addAll(new MandatoryValidator(), new
UserNameValidator());
Randahl
On 11/06/12 13.27, Tom Eugelink wrote:
> +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