question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation status reported on UI is not in sync with the binder

See original GitHub issue

With following code snippet:

  1. write a letter to input
  2. delete the letter from input
  3. click the button
  4. binder reports valid bean, UI shows invalid value in the TextField

Test code:


import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.router.Route;
import javax.validation.constraints.NotNull;
import java.util.Set;

@Route("")
public class MainView extends VerticalLayout {

    public static class Entity {

        @NotNull
        private String name;

        public void setName(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        @Override
        public String toString() {
            return "Entity, name: " + name;
        }

    }

    final TextField name = new TextField();

    public MainView() {

        final VerticalLayout layout = new VerticalLayout();
        name.setLabel("Type your name here:");

        Entity entity = new Entity();
        Binder<Entity> b = new BeanValidationBinder<>(Entity.class);
        b.bindInstanceFields(this);

        b.setBean(entity);

        Button button = new Button("Check validity");
        button.addClickListener(e -> {
            String msg = String.format("Binder.isValid: %s", b.isValid());
            Notification.show(msg);
        });

        add(name, button);

    }

}

Note, the code snippet is related to https://github.com/vaadin/framework/issues/9000 (which is valid for Flow as well), but the issue here is different.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
Legiothcommented, May 18, 2018

I think it would be fine to make setRequiredIndicatorVisible(true) overwrite checkValidity() to something that only looks at the invalid property, and then setRequiredIndicatorVisible(false) removes that overwrite.

If you’re using e.g. <vaadin-text-field> without Binder and want to make it required, then you should use the TextField::setRequired method instead of setRequiredIndicatorVisible.

0reactions
mstahvcommented, May 18, 2018

I don’t have that could understanding of all small details currently, but if I got it right, I think this is a good start.

I hope we can then continue fixing vaadin/framework#9000 😉 It would be nice to have that fixed for LTS version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binding Data to Forms | Data Binding | Vaadin Docs
The Binder class allows you to define how the values in a business object are bound to fields in the UI. Binder reads...
Read more >
Using Binder IPC | Android Open Source Project
This page describes changes to the binder driver in Android 8, provides details on using binder IPC, and lists required SELinux policy.
Read more >
CRM: Sync – Veeva Product Support Portal
This section provides solution articles for Veeva CRM Sync issues. Veeva CRM mobile users initiate a sync process to send all their data......
Read more >
UIPL 03-04 Attachment - Unemployment Insurance
Cases where a claimant in continued claim status is reporting wages which may ... The ±2 percent error tolerance for validation was designed...
Read more >
Known Exploited Vulnerabilities Catalog | CISA
The vulnerabilities are due to insufficient validation of user-supplied ... SP1 and Sitefinity before 10.0.6412.0 does not properly protect Telerik.Web.UI.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found