vaadin / vaadin/framework

Bound bean is not updated when field listeners are called

Open
#8,683 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Stale workaround
Dominant language
Java
Stars
1.8k
Forks
717
Avg merge
2d 6h
Merged PRs (30d)
3

Description

If you have code like

Binder<OrderItem> binder = new Binder<>(OrderItem.class);
binder.forField(quantity).withConverter(converter).bind("quantity");
quantity.addValueChangeListener(e->{
  System.out.println(e.getNewValue());
  System.out.println(binder.getBean().getQuantity());
});

....

binder.setBean(new OrderItem());

you would assume that the both lines printed are the same, i.e. the bound bean is updated before the listener is triggered. This does not happen though, because the bound bean is always updated AFTER the listener is triggered. The root cause seems to be that BindingImpl.initFieldValue removes the listener added while binding the field, and re-adds it after the other listener.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading BindingImpl.initFieldValue and trace how the binding listener is removed and re-added around field listeners. Reproduce the issue with the Binder example, then verify that the bound bean is updated before the listener observes the value and add or update a regression test for that ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.