Skip to content

AceEditor.getValue() is not up-to-date after addAceChangedListener() listener notified #35

Description

@archiecobbs

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

  1. Register listener
  2. Display e.getValue() and compare to this.ace.getValue()
  3. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions