Intended: In a Vaadin 23 application I'd like to get informed when the value of an HTML attribute is changed.
What I tried: I created this input formula:
// Text input field
Input input = new Input();
input.setId("myInputField");
Element textInput = input.getElement();
// Change listener for property "value"
// Works well for manual input
// BUT doesn't work for JavaScript changes
textInput.addPropertyChangeListener("value", "change",
e -> {System.out.println(e.getValue());}
);
// Button that changes the value of attribute "value"
Button button = new Button("Change value");
button.addClickListener(e -> {UI.getCurrent().getPage().executeJs(
"document.getElementById('myInputField').setAttribute('value','hello');"
);});
this.add(input, button);
What does work: When the user types "something" into the input field then the server prints "something" to the console. This is intended and observed. OK.
What does NOT work: When the user pushes the button then the content of the input field is "hello" (OK). But the PropertyChangeListener does not fire an event, so the server does not print anything to the console.
Question: Is there a way to get the PropertyChangeListener fire an event, even if the attribute's value has been changed by JavaScript?