Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeanValidationBinder is not marking @NotEmpty field as required if a validator is present that fails for the empty value #14161

Open
Dudeplayz opened this issue Jul 11, 2022 · 0 comments

Comments

@Dudeplayz
Copy link
Contributor

Dudeplayz commented Jul 11, 2022

Description of the bug

The problem is, that as soon a Validator is added to the binding or the bound field has a validator that fails for the emptyValue of the field, the field isn't marked asRequired anymore. The current Unit tests are just covering the @NotNull annotation, but not the NotEmpty annotation. This is in my eyes wrong behavior and could create trouble, as soon as vaadin/flow-components#3406 is implemented.
Issue for current implementation: vaadin/framework#9000 (comment)

Expected behavior

A field that is bound to a with @NotEmpty property should be marked as required, regardless if a Validator is present or not.

Minimal reproducible example

data class Example(
        @get:NotEmpty
        var property1: String = "",
        @get:NotEmpty
        var property2: String = ""
)

@Route("example")
class ExampleView : VerticalLayout() {

    val field1 = TextField("Field 1")
    val field2 = TextField("Field 2")
    val binder = BeanValidationBinder(Example::class.java)

    init {
        binder.forField(field1).bind("property1")
        binder.forField(field2).withValidator { value, context ->
            if (value.length < 5) ValidationResult.error("to short") else ValidationResult.ok()
        }.bind("property2")
        add(field1, field2)
    }

}

Result:
image

Versions

  • Vaadin / Flow version: 23.1.3
  • Java version: 11
  • OS version: Win 11 / Debian 11
  • Browser version (if applicable): Up to date Vivaldi / Edge
  • Application Server (if applicable): vertx-vaadin

Credits to @mcollovati for finding the related issues and validating the found behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Normal Priority (P2)
Development

No branches or pull requests

2 participants