diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-10-07 13:31:44 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-10-07 13:31:44 +0000 |
commit | 3e198eae20d1dfc8b136e58a842393ca49eafc83 (patch) | |
tree | f55aa63fef2046c70e7c4662788ef8bb2391b565 /src/com | |
parent | c380aabda7019369abb29d3cbdab0daf777dd16b (diff) | |
download | vaadin-framework-3e198eae20d1dfc8b136e58a842393ca49eafc83.tar.gz vaadin-framework-3e198eae20d1dfc8b136e58a842393ca49eafc83.zip |
#6588 quick fix, still need to re-evaluate and test the solution
svn changeset:21650/svn branch:6.7
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VTextField.java | 69 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractTextField.java | 50 |
2 files changed, 90 insertions, 29 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..41d48041fc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java @@ -41,6 +41,8 @@ public class VTextField extends TextBoxBase implements Paintable, Field, KeyDownHandler { public static final String VAR_CUR_TEXT = "curText"; + + public static final String ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS = "nvc"; /** * The input node CSS classname. */ @@ -244,10 +246,46 @@ 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 = uidl.getStringVariable("text"); + + /* + * We skip the text content update if field has been repainted, but text has + * not been changed. Additional sanity check verifies there is no change + * in the que (in which case we count more on the server side value). + */ + if (!(uidl.getBooleanAttribute(ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS) && valueBeforeEdit != null && text + .equals(valueBeforeEdit))) { + updateFieldContent(text); + } + + + if (uidl.hasAttribute("selpos")) { + final int pos = uidl.getIntAttribute("selpos"); + final int length = uidl.getIntAttribute("sellen"); + /* + * Gecko defers setting the text so we need to defer the selection. + */ + Scheduler.get().scheduleDeferred(new Command() { + public void execute() { + setSelectionRange(pos, length); + } + }); + } + + // Here for backward compatibility; to be moved to TextArea. + // Optimization: server does not send attribute for the default 'true' + // state. + if (uidl.hasAttribute("wordwrap") + && uidl.getBooleanAttribute("wordwrap") == false) { + setWordwrap(false); + } else { + setWordwrap(true); + } + } + + private void updateFieldContent(final String text) { setPrompting(inputPrompt != null && focusedTextField != this - && (text == null || text.equals(""))); + && (text.equals(""))); if (BrowserInfo.get().isFF3()) { /* @@ -288,30 +326,7 @@ public class VTextField extends TextBoxBase implements Paintable, Field, setText(fieldValue); } - lastTextChangeString = valueBeforeEdit = uidl.getStringVariable("text"); - - if (uidl.hasAttribute("selpos")) { - final int pos = uidl.getIntAttribute("selpos"); - final int length = uidl.getIntAttribute("sellen"); - /* - * Gecko defers setting the text so we need to defer the selection. - */ - Scheduler.get().scheduleDeferred(new Command() { - public void execute() { - setSelectionRange(pos, length); - } - }); - } - - // Here for backward compatibility; to be moved to TextArea. - // Optimization: server does not send attribute for the default 'true' - // state. - if (uidl.hasAttribute("wordwrap") - && uidl.getBooleanAttribute("wordwrap") == false) { - setWordwrap(false); - } else { - setWordwrap(true); - } + lastTextChangeString = valueBeforeEdit = text; } protected void onCut() { diff --git a/src/com/vaadin/ui/AbstractTextField.java b/src/com/vaadin/ui/AbstractTextField.java index 4ed76d367b..62904330c2 100644 --- a/src/com/vaadin/ui/AbstractTextField.java +++ b/src/com/vaadin/ui/AbstractTextField.java @@ -54,7 +54,8 @@ public abstract class AbstractTextField extends AbstractField implements private String inputPrompt = null; /** - * The text content when the last messages to the server was sent. + * The text content when the last messages to the server was sent. Cleared + * when value is changed. */ private String lastKnownTextContent; @@ -136,6 +137,17 @@ public abstract class AbstractTextField extends AbstractField implements getTextChangeEventMode().toString()); target.addAttribute(VTextField.ATTR_TEXTCHANGE_TIMEOUT, getTextChangeTimeout()); + if (lastKnownTextContent != null) { + /* + * The field has be repainted for some reason (e.g. caption, + * size, stylename), but the value has not been changed since + * the last text change event. Let the client side know about + * the value the server side knows. Client side may then ignore + * the actual value, depending on its state. + */ + target.addAttribute( + VTextField.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS, true); + } } } @@ -446,6 +458,18 @@ public abstract class AbstractTextField extends AbstractField implements @Override protected void setInternalValue(Object newValue) { if (changingVariables && !textChangeEventPending) { + + /* + * TODO check for possible (minor?) issue (not tested) + * + * -field with e.g. PropertyFormatter. + * + * -TextChangeListener and it changes value. + * + * -if formatter again changes the value, do we get an extra + * simulated text change event ? + */ + /* * Fire a "simulated" text change event before value change event if * change is coming from the client side. @@ -467,12 +491,34 @@ public abstract class AbstractTextField extends AbstractField implements lastKnownTextContent = newValue.toString(); textChangeEventPending = true; } - firePendingTextChangeEvent(); } + + /* + * Reset lastKnownTextContent field on value change. We know the value + * now. + */ + lastKnownTextContent = null; super.setInternalValue(newValue); } + @Override + public void setValue(Object newValue) throws ReadOnlyException, + ConversionException { + super.setValue(newValue); + /* + * Make sure w reset lastKnownTextContent field on value change. The + * clearing must happen here as well because TextChangeListener can + * revert the original value. Client must respect the value in this + * case. AbstractField optimizes value change if the existing value is + * reset. Also we need to force repaint if the flag is on. + */ + if(lastKnownTextContent != null) { + lastKnownTextContent = null; + requestRepaint(); + } + } + private void handleInputEventTextChange(Map<String, Object> variables) { /* * TODO we could vastly optimize the communication of values by using |