Skip to content

DatePicker looses value with readBean(null) is invoked even if it is set later #7227

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

Closed
erikcsik opened this issue Mar 19, 2025 · 2 comments
Closed

Comments

@erikcsik
Copy link

erikcsik commented Mar 19, 2025

Description of the bug

Hi,

We have a datepicker binded, if within the same request flow the binder readbean is invoked two times:
readBean(null);
readBean(myBean);
The datepicker looeses value even if the myBean.getDateField() returns a valid localdate.

Expected behavior

If the second readBean object contains valid value for the binded field it should be filled for the DatePicker.

Minimal reproducible example

    private TextField textField = new TextField();
    private Button button = new Button("Test");
    DatePicker datePick = new DatePicker();
    Binder<MyBean> binder = new Binder<MyBean>(MyBean.class);

    public HelloWorldView() {
        add(textField, datePick, button);
        binder.forField(textField).bind("name");
        binder.forField(datePick).bind("localDate");
        MyBean myBean = new MyBean();
        myBean.setLocalDate(LocalDate.now());
        myBean.setName("Test");
        binder.readBean(myBean);
        button.addClickListener(e -> {
            MyBean myBean2 = new MyBean();
            try {
                binder.writeBean(myBean2);
            } catch (ValidationException ex) {
                throw new RuntimeException(ex);
            }
            binder.readBean(null);
            binder.readBean(myBean2);
        });
    }

    public static class MyBean {
        private LocalDate localDate;
        private String name;

        public LocalDate getLocalDate() {
            return localDate;
        }

        public void setLocalDate(LocalDate localDate) {
            this.localDate = localDate;
        }

        public String getName() {
            return name;
        }

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

Versions

  • Vaadin / Flow version: 24.6.7
  • Java version: 21
@mcollovati mcollovati transferred this issue from vaadin/flow Mar 19, 2025
@TatuLund
Copy link
Contributor

The workaround is to postpone the second read after next client round trip using e.g.

        button.addClickListener(e -> {
            MyBean myBean2 = new MyBean();
            try {
                binder.writeBean(myBean2);
            } catch (ValidationException ex) {
                throw new RuntimeException(ex);
            }
            binder.readBean(null);
            getElement().executeJs("setTimeout(function() { }, 0)").then(result -> binder.readBean(myBean2));
        });

@vursen
Copy link
Contributor

vursen commented Apr 2, 2025

Seems to be the same issue as #7250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants