-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
AceEditor.getValue() is not up-to-date after addAceChangedListener() listener notified #35
Comments
Good Evening @archiecobbs, First of all thank you for this detailed issue. But this is intended and not a bug. The The I implemented the So instead of using the If you need further assistance, don't hesitate to ask. Have a great weekend, |
Hi David, OK thanks for the explanation - that makes sense. Not sure if what you've explained is properly documented though... you may want to consider adding a note to the Javadoc for Also, while I understand that |
ace/src/main/java/de/f0rce/ace/AceEditor.java Lines 75 to 99 in 3f24eb8
In the constructor of the Ace Editor the Blur Listener (and the so called Sync Listener) are added to the editor. All the other events can be used by you for specific use cases and do not update the value internally. The reason is to keep (as I said) the communication between client and server to a minimum. Out of curiosity, why wouldn't you use |
Hi David,
That's totally understandable. I'm still wondering about the answer to this question though:
In other words, if there is an Put another way, the following sequence doesn't make sense to me:
This is just needlessly inconsistent. By "needlessly" I mean it can be fixed without adding any network traffic.
It's because of the design of |
On Fri, Sep 16, 2022 at 8:20 AM urkl ***@***.***> wrote:
It's because of the design of CustomField. Then listener being notified
triggers a call to this.updateValue() which does not take any parameters.
To pass along the value from the listener would require a hack using a
ThreadLocal or whatever.
@archiecobbs <https://github.com/archiecobbs> did you resolved issues
with custom field?
No, now I'm just updating the field on loss of focus.
Here is my CustomField implementation:
/**
* Syntax highlighting JS editor.
*/
@SuppressWarnings("serial")
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.addBlurListener(e -> this.updateValue());
this.add(ace);
}
@OverRide
public void setHeight(String height) {
this.ace.setHeight(height);
super.setHeight(height);
}
@OverRide
public void setHeight(float height, Unit unit) {
this.ace.setHeight(height, unit);
super.setHeight(height, unit);
}
// CustomField
@OverRide
protected String generateModelValue() {
return this.ace.getValue();
}
@OverRide
protected void setPresentationValue(String newValue) {
this.ace.setValue(newValue);
}
}
…-Archie
--
Archie L. Cobbs
|
Archie thank you for this. |
Describe the bug
I have a Vaadin
CustomField
that wraps anAceEditor
- very straightforward.In order to keep the
CustomField
's value up-to-date, I register a listener.It looks something like this:
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, thenupdateValue()
is invoked (shown above), and (as documented byCustomField
) it invokesgenerateModelValue()
which invokesthis.ace.getValue()
(shown above) but then the value returned bythis.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
e.getValue()
and compare tothis.ace.getValue()
Expected behavior
When a listener is notified,
this.ace.getValue()
should always equale.getValue()
.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: