aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-09-27 09:43:44 +0000
committerLeif Åstrand <leif@vaadin.com>2011-09-27 09:43:44 +0000
commit849d5041e4d0de462058227f23a4d3ca6d54db2a (patch)
tree4ec7c8a78ea235e9914909577f52b2e22007039a /src
parentb112e78d96dd343095f6322a9923da726851b233 (diff)
downloadvaadin-framework-849d5041e4d0de462058227f23a4d3ca6d54db2a.tar.gz
vaadin-framework-849d5041e4d0de462058227f23a4d3ca6d54db2a.zip
#6588 Repainting in TextChangeListener will send wrong value to client
svn changeset:21332/svn branch:6.7
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTextField.java13
-rw-r--r--src/com/vaadin/ui/AbstractTextField.java34
2 files changed, 44 insertions, 3 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
index 8bc655f39f..f7edf5705f 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
@@ -64,6 +64,7 @@ public class VTextField extends TextBoxBase implements Paintable, Field,
private static final String CLASSNAME_PROMPT = "prompt";
private static final String ATTR_INPUTPROMPT = "prompt";
public static final String ATTR_TEXTCHANGE_TIMEOUT = "iet";
+ public static final String ATTR_TEXT_CHANGED = "textChanged";
public static final String VAR_CURSOR = "c";
public static final String ATTR_TEXTCHANGE_EVENTMODE = "iem";
private static final String TEXTCHANGE_MODE_EAGER = "EAGER";
@@ -244,8 +245,16 @@ public class VTextField extends TextBoxBase implements Paintable, Field,
setColumns(new Integer(uidl.getStringAttribute("cols")).intValue());
}
- final String text = uidl.hasVariable("text") ? uidl
- .getStringVariable("text") : null;
+ final String text;
+ if (uidl.hasAttribute(ATTR_TEXT_CHANGED)
+ && uidl.getBooleanAttribute(ATTR_TEXT_CHANGED)
+ && uidl.hasVariable("text")) {
+ // Use value from UIDL only if something hans changed on the server
+ text = uidl.getStringVariable("text");
+ } else {
+ // Use what we already have if no change from the server
+ text = prompting ? null : getText();
+ }
setPrompting(inputPrompt != null && focusedTextField != this
&& (text == null || text.equals("")));
diff --git a/src/com/vaadin/ui/AbstractTextField.java b/src/com/vaadin/ui/AbstractTextField.java
index 4ed76d367b..c5f24ea4bb 100644
--- a/src/com/vaadin/ui/AbstractTextField.java
+++ b/src/com/vaadin/ui/AbstractTextField.java
@@ -92,6 +92,12 @@ public abstract class AbstractTextField extends AbstractField implements
*/
private boolean changingVariables;
+ /**
+ * Track whether the value on the server has actually changed to avoid
+ * updating the text in the input element on every repaint
+ */
+ private boolean localValueChanged = true;
+
protected AbstractTextField() {
super();
}
@@ -123,6 +129,11 @@ public abstract class AbstractTextField extends AbstractField implements
throw new IllegalStateException(
"Null values are not allowed if the null-representation is null");
}
+
+ if (localValueChanged || target.isFullRepaint()) {
+ target.addAttribute(VTextField.ATTR_TEXT_CHANGED, true);
+ localValueChanged = false;
+ }
target.addVariable(this, "text", value);
if (selectionPosition != -1) {
@@ -213,7 +224,8 @@ public abstract class AbstractTextField extends AbstractField implements
if (newValue != oldValue
&& (newValue == null || !newValue.equals(oldValue))) {
boolean wasModified = isModified();
- setValue(newValue, true);
+ // Don't update the local change flag
+ super.setValue(newValue, true);
// If the modified status changes, or if we have a
// formatter, repaint is needed after all.
@@ -238,6 +250,26 @@ public abstract class AbstractTextField extends AbstractField implements
}
@Override
+ protected void setValue(Object newValue, boolean repaintIsNotNeeded)
+ throws ReadOnlyException, ConversionException {
+ if (isChanged(newValue, getValue())
+ || isChanged(newValue, lastKnownTextContent)) {
+ // The client should use the new value
+ localValueChanged = true;
+ if (!repaintIsNotNeeded) {
+ // Repaint even if super.setValue doesn't detect any change
+ requestRepaint();
+ }
+ }
+ super.setValue(newValue, repaintIsNotNeeded);
+ }
+
+ private static boolean isChanged(Object newValue, Object oldValue) {
+ return oldValue != newValue
+ && (newValue == null || !newValue.equals(oldValue));
+ }
+
+ @Override
public Class getType() {
return String.class;
}