-
-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Describe the bug
I have a Vaadin CustomField that wraps an AceEditor - very straightforward.
In order to keep the CustomField's value up-to-date, I register a listener.
It looks something like this:
public class JavascriptField extends CustomField<String> {
private final AceEditor ace = new AceEditor();
public JavascriptField() {
this.ace.setMode(AceMode.javascript);
this.ace.setTheme(AceTheme.chrome);
this.ace.setShowPrintMargin(false);
this.ace.addAceChangedListener(e -> this.updateValue());
this.add(ace);
}
// CustomField
@Override
protected String generateModelValue() {
return this.ace.getValue();
}
@Override
protected void setPresentationValue(String newValue) {
this.ace.setValue(newValue);
}
...The bug is that when a listener notification comes, the event value e.getValue() is up-to-date with whatever was just entered into the GUI. However, then updateValue() is invoked (shown above), and (as documented by CustomField) it invokes generateModelValue() which invokes this.ace.getValue() (shown above) but then the value returned by this.ace.getValue() is out of date.
So the end result is that the CustomField always has a stale value.
All Vaadin notifications that I've encountered in the past are "up to date" in the sense that if you query the state directly from the event handler, that state is consistent, i.e., up-to-date, with respect to the change you're being notified about.
However AceEditor doesn't seem to provide this guarantee, which seems like a bug.
To Reproduce
- Register listener
- Display
e.getValue()and compare tothis.ace.getValue() - Notice they are not the same
Expected behavior
When a listener is notified, this.ace.getValue() should always equal e.getValue().
Desktop (please complete the following information):
- OS: Mac OS 12.5
- Browser Firefox 103.0.1
- Add-on version 3.3.3