import com.vaadin.ui.UI;
import elemental.json.JsonObject;
+import elemental.json.JsonValue;
/**
* An abstract base class for ClientConnector implementations. This class
public int hashCode() {
return super.hashCode();
}
+
+ /**
+ * Sets the expected value of a state property so that changes can be
+ * properly sent to the client. This needs to be done in cases where a state
+ * change originates from the client, since otherwise the server-side would
+ * fail to recognize if the value is changed back to its previous value.
+ *
+ * @param propertyName
+ * the name of the shared state property to update
+ * @param newValue
+ * the new diffstate reference value
+ */
+ protected void updateDiffstate(String propertyName, JsonValue newValue) {
+ if (!isAttached()) {
+ return;
+ }
+
+ JsonObject diffState = getUI().getConnectorTracker().getDiffState(this);
+ if (diffState == null) {
+ return;
+ }
+
+ assert diffState.hasKey(propertyName) : "Diffstate for "
+ + getClass().getName() + " has no property named "
+ + propertyName;
+
+ diffState.put(propertyName, newValue);
+ }
}
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;
+import elemental.json.Json;
+
/**
* Abstract base class for text input components.
*
@Override
public void setText(String text, int cursorPosition) {
- getUI().getConnectorTracker().getDiffState(AbstractTextField.this)
- .put("text", text);
+ updateDiffstate("text", Json.create(text));
+
lastKnownCursorPosition = cursorPosition;
setValue(text, true);
}
import com.vaadin.ui.declarative.DesignFormatter;
import com.vaadin.util.ReflectTools;
+import elemental.json.Json;
+
/**
* A generic button component.
*
// Makes sure the enabled=false state is noticed at once - otherwise
// a following setEnabled(true) call might have no effect. see
// ticket #10030
- getUI().getConnectorTracker().getDiffState(Button.this)
- .put("enabled", false);
+ updateDiffstate("enabled", Json.create(false));
}
};
import com.vaadin.shared.ui.richtextarea.RichTextAreaState;
import com.vaadin.ui.declarative.DesignContext;
+import elemental.json.Json;
+
/**
* A simple RichTextArea to edit HTML format text.
*/
private class RichTextAreaServerRpcImpl implements RichTextAreaServerRpc {
@Override
public void setText(String text) {
- getUI().getConnectorTracker().getDiffState(RichTextArea.this)
- .put("value", text);
+ updateDiffstate("value", Json.create(text));
if (!setValue(text, true)) {
// The value was not updated, this could happen if the field has
// been set to readonly on the server and the client does not
* Sets the value of this object. If the new value is not equal to
* {@code getValue()}, fires a {@link ValueChangeEvent}. Throws
* {@code NullPointerException} if the value is null.
- *
+ *
* @param value
* the new value, not {@code null}
* @throws NullPointerException
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;
+import elemental.json.Json;
+
/**
* A component for selecting a numerical value within a range.
*
*
* See #12133.
*/
- getUI().getConnectorTracker().getDiffState(Slider.this).put("value",
- value);
+ updateDiffstate("value", Json.create(value));
try {
setValue(value, true);